开发者

Regarding PageMethod in asp.net

I have a few questions regarding PageMethods. I am learning the use of 开发者_开发问答PageMethod.

  1. Why can't PageMethods be called from user controls?
  2. If server-side controls and viewstate can not be access from PageMethods, what is the use of PageMethods? If I need to update the UI with javascript after response back from a PageMethod, then we have to write lots of script all the time when we work with PageMethod.

So please tell me in what kind of situation we should use PageMethod.


Here is a simple example of the benefit of a PageMethod, inspired by functionality stackoverflow.com has.

When you type in the Tags textbox, tags that match some of the text you started to enter begin to appear. This could be handled in a PageMethod (although, in SO's case, it would not be, as they use this functionality in multiple places on the site, so it is very likely its very own web service). No extra scripting is needed: you simply call the PageMethod in your jQuery AJAX call like you would any other web service, except the URL for the service is the same as the page (plus the method name).

For an example of this, see http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜