从 ASP.NET 中的静态方法更改显示的数据
我有两个用户控件位于页面上,用于确定应显示哪个。用户控件生成一些 html,这些 html 被传递到 asp:literal 中,然后通过 javascript 进行操作。由于缺乏允许我在项目中使用的合适控件,所以采用这种方式完成。
当用户单击视图更改按钮时,将从控件的 javascript 调用主页(包含控件的页面)上的 WebMethod。从这里,调用控件上的静态方法。然后,控件需要重新生成 html 并将其放入 asp:literal 中才能完成视图更改。
我的问题是我处于控件页面上的静态方法中,并且无法访问非静态 genorateHtml 函数。我尝试过单例模式但没有成功(这可能是由于实施不当造成的)。关于如何拨打此电话有什么想法吗?谢谢!
I have two user controls that sit on a page which determines which should be displayed. The user controls generate some html that is passed into an asp:literal and subsequently manipulated via javascript. It is done this way due to the lack of a suitable control that I am allowed to use on the project.
When a user clicks a view change button, a WebMethod is called on the main page (the one that holds the controls) from the control's javascript. From here, a static method on the control is called. The control then needs to regenerate the html and place it into the asp:literal for the view change to be complete.
My problem is that I am in a static method on the control's page, and have no access to the non-static genorateHtml function. I have tried a singleton pattern with no success (this could have been due to improper implementation). Any ideas on how to make this call? THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我曾经在我从事的一个项目中遇到过类似的问题。我们最终采用的解决方案是实现 System.Web.UI.ICallbackEventHandler 并进行部分渲染,以根据参数仅返回所需的内容。 ICallbackEventHandler 在页面生命周期中运行。
当时我们遇到的唯一麻烦是与实现相关的性能问题,它回发整个表单而不仅仅是您想要的参数。
也许对您来说最好的方法是通过 这个方法,其中它们从静态方法呈现控件。这可能会满足您的需求。
希望这有帮助!
I used to hit similar issues at with one of the projects i worked on. The solution we ended up adopting was implementation of System.Web.UI.ICallbackEventHandler with partial rendering to return just the needed content depending on arguments. ICallbackEventHandler runs in the page lifecycle.
The only trouble we had then was performance issues relative to implementation which posts back the whole form instead of just the arguments you want.
Maybe the best way for you would be through this method in which they render the control from a static method. That would probably suit your needs.
Hope this helps!