calling an ascx page method using jquery calling an ascx page method using jquery asp.net asp.net

calling an ascx page method using jquery


No, because ascx controls don't represent a real URL that can be accessed from a client machine. They're purely server-side meant to embed in other pages.

What you might want to do is just have an aspx page that provides the same snippet of html you currently have in your ascx file. An aspx page doesn't necessarily need to provide a full html document (<html><body> etc.), it can just render the user control you're interested in.

We use this technique all the time with the ingrid plugin, which requires a callback url for the table contents.


I don't think it's possible by requesting the ascx file directly--i.e. supplying "MyControl.ascx" as the url parameter to $.ajax(..). The ascx file isn't exposed directly by the web server.

You can, I believe, supply the url of the aspx page containing the user control--i.e. if an instance of MyControl.ascx lives on MyPage.aspx you would have to supply "MyPage.aspx" as the url parameter. It sounds like that might defeat the purpose for what you're trying to accomplish though.

EDIT: What Clyde said below seems like a good idea. I'm doing something similar myself by including the ascx control on a page whose job is more or less just to host it for access from client-side script.


I don't think it will be possible, as user controls aren't meant to be accessible externally (outside of a page). I suggest just using a script service (a web service).