开发者

How common usage are Page Methods in ASP.NET 4?

How common usage are Page Methods in ASP.开发者_开发问答NET 4?

I would like an example of how it's used (not a code sample).


I don't know about how common, but check out this example: http://aspalliance.com/1922_PageMethods_In_ASPNET_AJAX.all

Use page methods if you don't want to publicly expose a web service, and creating a web method that's specifically only to that page, IMHO. So for instance, I need web service features for one page only, that's when I create a page method. If I need something reusable in two pages, but don't want to publically expose it, I create a helper and the web method wraps the helper.

Otherwise, if you are looking to create a dynamic web site and share information, go with a traditional ASMX or WCF service.

HTH.


In your ASPX file you'll need this line.

 <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />

In your code behind define a method marked as a WebMethod.

[WebMethod]
public static void MyMethod()
{
   //code.....

Then to call that method in JavaScript.

PageMethods.SendForm(SuccessCallBack, FailureCallBack);

There are more advanced examples out there - just Google it.


I don't know about usage, but this is a very basic and clear example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜