I have a .aspx form in which I have a combobox holding subject I retrive from a DB-table.
A submit button clicking on which questions related to that subject are viewed in a gridview.
I do it by calling the function FillGrid() in the button click event.
I also have pageindexchanging for my gridview in which FillGrid() is again called.
In my FillGrid() function I have used a try catch block. If an error occurs I want to redirect the page to error page using Response.Redirect(). The problem is this response.redirect is not working. One of the reasons of it is that on button click the form is posted twice. Because after reaching to response.redirect statement flow comes back to button click where FillGrid is called().
How can I solve this? Or to put simply, how can I prevent double posting of the form?
For example you need to link index.aspx
.
So you write this:
Response.Redirect("index.aspx", true);
But Response.redirect
is not working. Now go to design view select the button which you want to set Response.redirect
and press F4 that will open Button Properties then you need to find PostBackUrl
option and then locate your URL that you want.
See this image:
Well, do this...
Response.Redirect("~/err.aspx", false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Now the original page won't be posted back to the browser and you will be redirected to the new page..
The problem with Response.Redirect("~/err.aspx", true);
is that an exception is formed that way, which may send the control to the catch block..
•Another way is of course Server.Transfer() but I don't think you wanted that.
I have encountered exactly same problem. Redirect was not working because of content page's master page has errors. This is sample code:
FormsAuthentication.SetAuthCookie(loginUserDetail.UserName, false);
Response.Redirect(FormsAuthentication.DefaultUrl, false);
FormsAuthentication.DefaultUrl value is "/membersarea/wellcome.aspx" and wellcome.aspx has a master page named, Site.master.
Site.master had javascript errors, so Response.Redirect command was not working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With