Search code examples
javascriptdopostback

doPostback and then navigate to another page


I am trying to call __doPostBack from within JavaScript and then navigate to another page. The script I have is:

$(document).ready(function() {  
   $("a.change-link").click(function(){          
             __doPostBack("","");  
             location.href='pageToGoTo';                                                                                            
   });

});

The code is not getting to the location.href='pageToGoTo' line after the post back.

Is there anyway to achieve this functionality?

Thanks


Solution

  • location.href='pageToGoTo'; will never be executed since you're posting the entire form back to the server. You'll need to redirect the request on the server-side.

    Response.Redirect = "pageToGoTo";