An alternative way to use the page method inside an asp.net user control

Is there a way by which I can implement the functionality of the page method inside a user control.

Any help is appreciated, thanks :)

+3
source share
2 answers

The easiest way is probably to add the functionality you need in the webservice and then use the scriptservice attribute to make it available.

It works similar to the page method.

Quite an extensive example here .

<asp:ScriptManager> <Services> <asp:ServiceReference Path="~/MyWs.asmx" /> </Services> </asp:ScriptManager> 

Then you can call your web methods in JS: MyNamespace.MyWs.MyMethod ();

+5
source

What works for me is to put my WebMethods in a custom class derived from System.Web.UI.Page

 public class MyPage : System.Web.UI.Page { [WebMethod] public static bool MyMethod(string value) { return true; } } 

Then, when I have a page containing user control that this WebMethod should use, I retrieve this page from my custom page class instead of System.Web.UI.Page.

0
source

All Articles