Thomas
Thomas

Reputation: 34188

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.

Upvotes: 1

Views: 538

Answers (1)

Steve Costello
Steve Costello

Reputation: 380

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

Upvotes: 2

Related Questions