QasimRamzan
QasimRamzan

Reputation: 397

I don't want to postback my .aspx page

I want to go from the First.aspx page to the second.aspx page without postback. How should I handle this situation? Is it possible or not? I am doing this, but I don't know how to get a response from the handler.

Sending a request to handler:

<script type="text/javascript" src="jqure.js"></script>
 function goMoz() { 
      $.post("Handler1.ashx", callback);
      function callback(data) { 
      alert(data);
    }
</script>

In the body of the html I'm using html <a id="buton" onclick="goMoz()">

What must I do in the handler to go to the second.aspx page?

I am also using window.location = "Registration.aspx"; in goMoz().

Upvotes: 0

Views: 386

Answers (2)

Andre Loker
Andre Loker

Reputation: 8408

A few things: first, your javascript example code has syntax errors, you're missing a closing }.

Second: If you want to load the content of a different page and use the content inside the current page, check out the different Ajax functions in jquery, for example the load:

   function goMoz() {
       $.post("Handler1.ashx", callback);

       function callback(data) {
           alert(data);
           // Load response of "second.aspx" 
           // into element with ID results.
           $("#results").load("second.aspx");
       }
   }

Note that you should be careful when loading a "whole page" into an element of the current page. If the "whole page" contains full HTML markup with html, body etc. tags then your HTML can easily become invalid. You can however define what part of the page to actually grab and insert in the current page by adding a selector after the url:

$("#results").load("second.aspx #whatToLoad");

This would only load the content of whatToLoad element in the results element on the current page.

Upvotes: 1

in aspx page

 function goMoz(islem) {
            $.ajax(
                {
                    type: "POST",
                    url: "../Handler1.ashx",
                    data: "islem=" + islem,
                    dataType: "html",
                    success: function (data) {

                      alert(data)

                    },
                    error: function (data) {
                        alert("Error")
                    }
                });
        };

in ashx handeler.

  public void ProcessRequest(HttpContext context)
        {
            string isl= context.Request.Form["islem"];
             .....same codes
            context.Response.Write("return values");


          }

Hope it helpful

Upvotes: 0

Related Questions