开发者

ASP.NET: How to call non-static page method with client AJAX script?

开发者 https://www.devze.com 2022-12-16 09:05 出处:网络
How can this be done? Does this exclu开发者_如何学Cde the UpdatePanel functionality when it\'s done?The reason that it supports only static methods is that no page is instantiated. This means that the

How can this be done? Does this exclu开发者_如何学Cde the UpdatePanel functionality when it's done?


The reason that it supports only static methods is that no page is instantiated. This means that there is no page instance, so of course instance methods cannot be called. This also means that UpdatePanel functionality does not run when you do this.

A workaround is that within your static method you can instantiate the page itself and then do whatever you want. However, keep in mind that things like the page lifecycle won't run.

To get the current context you can use HttpContext.Current, which is a static property. Once you have that you can access things like session or profile and get information about the state of the site.

If you tell us more about your scenario there might be a better solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消