How to call WebMethod for a control in javascript

I am trying to call WebMethod (GetData ()) for a control on 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>

uc: Control code:

    [WebMethod()]
    [ScriptMethod()]
    protected void GetData()
    {
        //stuff happens here
    }

I can’t figure out which selector to use. I have several controls on the page and I want to call them at different times. Which selector or command do I use to run this WebMethod?

+3
source share
3 answers

As far as I understand, it is impossible to call webmethod / pagemethod a child / user control.

If you move this web method to the parent aspx, you will 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);
  }
});
+2
source

, ControlID, , , asp.net

$("[id$='_ControlIDHere']")

EDIT: , , , ,

0

JavaScript ASP.NET . < uc1: Control > .aspx , , . HTML-, JavaScript.

HTML- (.. β†’ ) , HTML, , .

0

Source: https://habr.com/ru/post/1788292/


All Articles