I'm trying to call a WebMethod (GetData()) for a control in a web page using javascript.
<script type="text/javascript">
$(document).ready(function () {
//this selector needs fixed
$('<%= Control1.ClientID %>').GetData();
});
</script>
<tel:RadScriptManager ID="RadScriptManager1" runat="server" />
<tel:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<uc1:Control ID="Control1" runat="server" />
</tel:RadAjaxPanel>
The uc:Control code:
[WebMethod()]
[ScriptMethod()]
protected void GetData()
{
//stuff happens here
}
I can't figure out what kind of selector to use. I have multiple controls on the page, and i want to call them at different times. What kind of selector or what command do I use to run this WebMethod?
It is my understanding that it is not possible to call a webmethod/pagemethod on a child/user control.
If you were to move this web method to the parent aspx, you would need to do something like this:
jQuery.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: '{}',
dataType: 'json',
url: 'MyPage.aspx/SomePageMethod',
success: function(result){
alert(result);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With