I am working in Asp.Net using C# and I have a [WebMethod]
defined in a User Control. I don't want to use a web service.
How can I call a method with an [WebMethod]
attribute? I want to call it from a jQuery (Ajax) request.
I am working in Asp.Net using C# and I have a [WebMethod]
defined in a User Control. I don't want to use a web service.
How can I call a method with an [WebMethod]
attribute? I want to call it from a jQuery (Ajax) request.
You really should reconsider using a service if your goal is to centralize shared functionality.
ASMX services don't have any of the configuration burden that WCF services do (which is often what comes to mind when someone mentions "web service" now). If you use a simple ASMX "ScriptService", the code, development, configuration, etc will be nearly identical to what you're doing in ASPX files now, just centralized. ASMX ScriptServices and ASPX page methods are so similar that they literally share most of the same underlying backend code.
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.
You really should reconsider using a service if your goal is to centralize shared functionality.
ASMX services don't have any of the configuration burden that WCF services do (which is often what comes to mind when someone mentions "web service" now). If you use a simple ASMX "ScriptService", the code, development, configuration, etc will be nearly identical to what you're doing in ASPX files now, just centralized. ASMX ScriptServices and ASPX page methods are so similar that they literally share most of the same underlying backend code.
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.
© 2022 - 2024 — McMap. All rights reserved.