0

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

Jon
  • 3,173
  • 3
  • 39
  • 66
Thomas
  • 33,544
  • 126
  • 357
  • 626

2 Answers2

0

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.

Community
  • 1
  • 1
Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
0

It looks to me like you want to get HTML back from your response? Possibly so you can just set the contents of a div instead of having to build the html on the client. If that is the case, then make a new aspx page that contains your ascx and have the ascx databind in the page load of the aspx.

Al W
  • 7,539
  • 1
  • 19
  • 40