views:

635

answers:

3

hey..

i have a .aspx form in which i have a combobox holding subjects i retrive from DB table

a submit button cliking on which questions related to that subject are viewed in a gridview..

i do it by calling a function FillGrid() in button click event

i also have pageindexchanging for my gridview in which FillGrid() is again called.. ..

in my FillGrid() function i hv used try catch block if error occurs i want to redirect the page to error page using Response.Redirect()...the problem is this response.redirect is not working..in one of the reason of it that on button click the form is posted twice...coz 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 form?? thanx..

+1  A: 

Try this:

Response.Redirect("url");
Response.End;
Oded
That's the default behavior for Response.Redirect.
Jeff Sternal
Response.Redirect("url", true) is saying the same thing.
Marc
A: 

Have a look at this article.

Matt Joslin
A: 

I believe the behavior you are seeing is correct. A response.redirect is done through the browser. So when you get an error, the page is posted to the browser and the browser triggers the redirect. The redirect causes the page_load to fire again (this is the standard flow in ASP.NET).

While you can use Server.Transfer to get around this, I'd recommend using the error redirection built into ASP.NET. See this page for more information on what's available and how to use them.

Jeff Siver