Search code examples
c#jqueryasp.netascx

I have issue regarding ascx user control method calling by jquery


I have user control which is included in most of my aspx page. This user control shows huge data from database. Now I have decided to fetch that by jquery. I am very much familiar with jquery and how to call server side method by jquery. My problem is that I can not specify ascx file in jquery ajax post method. Like

function loadMore() {
    $.ajax({
        type: "POST",
        url: "Left.ascx/LoadData",
        data: "{PageIndex:1}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
        },

        error: function (request, status, error) {
            alert(request.responseText);
        }
    });
}

I can not call ascx code behind method by jquery because ASCX is not directly served via URL. I cannot write even C# code for loading & populating ascx from aspx server side method dynamically because it has been used in many aspx. So now I am in problem. No easy & good idea is coming to my mind...so I am stuck. Please show me the way to achieve it. Thanks


Solution

  • You cannot call the ascx method directly. What you have to do is call an aspx page method and from that call the user control method. This sounded familiar so I checked. I have an answer to a similar question here:

    Jquery .ajax async postback on C# UserControl

    which shows the way this can be done.