Question

I have code within a try/catch block with a redirect to another page. If any error happens, the catch also redirects to another page. When a user clicks on a submit button the page does not redirect anywhere. It does some sort of page refresh and stays on the same page. It happens sometimes. Other times, the button needs to be clicked a few times before the redirect is recognized and then it redirects to the SUCCESS Page. Any thoughts on why this is happening? Thanks.

try
{
    ...
    Response.Redirect("SOME PAGE SUCCESS", false);
}
catch (Exception ex)
{
    Response.Redirect("SOME PAGE FAIL");
}

A js script does a doPostBack to submit data to the server side.

setTimeout('__doPostBack(\'' + el.name + '\',\'' + args + lia + '\')', 500);
Was it helpful?

Solution 2

I had to redo the whole page. Apparently, there were too many setTimeout('__doPostBack()',500); calls within the javascript which refreshes the page randomly and does not allow the server to finish running through its code. Got rid of all of the __doPostBack calls into the server and used the asp.net controls and worked with the server directly for page submissions.

OTHER TIPS

You shouldn't use response.redirect inside of a try-catch block. Try setting a boolean variable in the try-catch block, then use the value of that variable in an if-then-else statement to redirect to the appropriate page after the end try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top