Call code after function from jquery in aspx

I want to call the codebehind function from jquery.

The aspx file name is group_master.aspx

jquery

    function populatecontrol(list, control) {
    var id = 0;
var GroupName=document.getElementById('<%=hdnGroupNameCheck.ClientID %>');
if (list.length > 0) {
    $.each(list, function (key, value) {

        var obj = JSON.parse(value);
        document.getElementById('<%=hdnGroupNameCheck.ClientID %>').value=obj.Second;
        control.html("Group already exist").append('<a id="editclick" href ="edit('+obj.Second+')">Click here to edit or enquire</a>');


    });
}
else
control.text="Group does not exist"
}

Editing ('+ obj.Second +') is an editing function in codebehind.

Thank,

+3
source share
3 answers

That sounds like the perfect candidate for Page Methods. See this guide for more details:

Using jQuery to directly call ASP.NET AJAX page methods

+3
source

You need to make the code behind the static method, and also mark it as [WebMethod] so that it is treated as a service method, and then uisng jQuery ajax call you can call the code behind the method, for example:

var loc = window.location.href;
$.ajax({
     type: 'POST',
      url: loc + "/GetMessage",
      data: "{}",
      contentType: "application/json; charset=utf-8"

    })
    .success(function (response) {
      alert(response.d);

    })
    .error(function (response) {
      alert(response.d);
    });

: http://www.codegateway.com/2012/05/jquery-call-page-codebehind-method.html

+2

I recommend using page methods. In short, you would create a web method in your code, behind which you would call jQuery logic.

See this link for an example: Page Methods in asp.net

0
source

All Articles