views:

40

answers:

2

I am working in asp.net using C# and I have a [WebMethod] defined in User Control. I dont want to use web service. My Question is : How can i call this any method which has [WebMethod] attribute? I want to call it from jQuery (Ajax) request.

Please help me

+2  A: 

You cannot call a page method declared within an ASCX user control. The page method would have to be declared in your aspx or expose it as a proper asmx web service.

redsquare
+1  A: 

You theoretically could, but it would get slightly messy and i wouldnt recommend it.
But what you could do is call the aspx page containing the control and pass a querystring parameter (like runfunc=1) which would be handled by the ascx control and run the function.
All other functionality would be run otherwise - and you could put all the html in a panel which is hidden if you called the "WebMethod" function.
This would also allow you to remove the WebMethod property on the function name.

danrichardson