Jquery ajax call to an aspx page method


I have two aspx page on my application. From the first one, lets say default.aspx, I have one button and one textbox. When I click the button I do an ajax call to the checkname.aspx as below

            function docheck() {

            var un = $('#username').val();


                url: "checkname.aspx",
                data: { name: un, method: 'checkname' },
                dataType: 'script',
                success: function (val) {

                    if (val == "No")
                        alert("not valid");



From checkname.aspx page I do the operations like below but it response is also adding the checkname.aspx page's html to the response so the success message of ajax call doesnt became what I wanted. How do I send just what the CheckName method send.


    protected void Page_Load(object sender, EventArgs e)

  NameValueCollection queries = HttpUtility.ParseQueryString(Request.QueryString.ToString());

    if(queries["method"] == "checkname")

protected void CheckName(string Name)
    if (Name == "ryu")


Thanks in advance,

Call HttpContext.Current.Response.End(); to end processing your aspx request, otherwise, all stuff after that call in Page_Load gets processed normally, thus you've got the results you've described.

But in general, follow the advices given by other people here, and work with your AJAX requests in different way.