0

I have a web page on which i am applying Ajax enabled update progress bar on submit button. In this submit button click i am doing some database operations and if operations are successful then page is server.transfer to another page.

My problem is that i have to implement progress bar on this submit button and page should redirect to another page. But i am getting page request manager exception on server .transfer. I can't use response.redirect due to some security features,Please give me solution or work around to avoid page request manager exception.

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
  • You are attempting a Server.Transfer within an AJAX (UpdatePanel or some such class) request? – Mike Guthrie Mar 27 '12 at 18:57
  • yes I am attempting a Server.Transfer within an AJAX (UpdatePanel).Is there any alternative to do Server.Transfer within an AJAX (UpdatePanel) because every time i am getting page request manager exception due to rendering of another page html tag. – deepak omar Mar 28 '12 at 05:05
  • You cannot transfer/redirect the page in the AJAX postback. The AJAX is expecting just the markup to replace the dynamic control, not an entire page, so your model won't work. Try replacing the UpdatePanel postback with a jQuery script, like [the answer to this question](http://stackoverflow.com/a/1538548/1223642). – Mike Guthrie Mar 28 '12 at 11:31

2 Answers2

0

As per my comment above, you cannot change pages within an AJAX postback. Instead, you will have to wait for the AJAX request to complete, to which you can send back the success/fail results of your database option. Using just the Client API exposed by the ScriptManager, you can then use the following script:

<script type="text/javascript">
<!--
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequest);
function EndRequest(sender, args) {
    // TODO: Validate args indicates success.
    var isSuccess = true;
    if (isSuccess)
        window.location = "SecondPage.aspx";
}
// -->
</script>

Place this script directly following your ScriptManager declaration, modify as per your needs to validate success and direct to the correct page.

Mike Guthrie
  • 4,029
  • 2
  • 25
  • 48
0

Thanks for your reply ,you have given a good suggestion ,i have also find out a solution for this problem which i want to share ,it worked fine for me.Because my problem is to maintain hidden variables and to server.transfer so i have put my code like this. I have put 2 buttons one inside update panel and another outside of update panel so when inside update panel button's click event will fire then it will do database operations and after successful db operations it will call a java script function from server side like this

protected void btnProceed_Click(object sender, EventArgs e)
    {
     //do your db operations
     //After successful operations call java script

      ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "displayNote","   <script language='JavaScript'>onAsyncPostclick();</script>", false);

}

Java script Code

<script type="text/javascript" language="javascript">
//ToDo: Used to call button on which we fire server.transfer
      function onAsyncPostclick() {
      var btnName = $get("<%=btnPostBack.ClientID%>").name;
      __doPostBack(btnName, "");
    }
</script>

In this JavaScript Code I have put postback call to another button which is outside of update panel and in that button's click event i am firing server .transfer to new page like this

    //Implemented for button Submit (outside of Update panel) click
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Server.Transfer("NewPage.aspx");
    }

In the above way i can call server.transfer on ajax enabled postback click and i saved my code from page request Manager exception .I think its a work around for the problem but it works fine for my requirements.