Get user control method and properties from static page method
So I have an ASP.NET user control that is using jQuery AJAX to call a method. Here's the jQuery:
$.ajax({
type: 'POST',
url: 'Default.aspx/AdvertClick',
data: '{"name":"test"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(result) {
//do something
}
});
Because it needs to call a static web method, I have the AdvertClick method in the Default.aspx page:
[WebMethod()]
public static string AdvertClick(string name)
{
return "";
}
In my AdvertClick method, I'm taking in a string value. I have a lot of data and methods in my user control that I need to access in order to do something with that string value. But because the method in my page is static, I can't access anything from my user control without creating a new instance of the control.
Is there any way I can access the user control methods? Sho开发者_运维问答uld I try a different AJAX technique? I hate that I have to call a method on the page, which then needs to access data from my control.
Move your static method AdvertClick code into a class, and then call it from your web method, and the control on the page. The work could be done in a class, so both can access it.
What exactly does the control do?
精彩评论