Response.Redirect triggers Page_Load

D

dwclark

I am having an issue when I trigger a Response.Redirect, the Page_Load
fires on the page where the Response.Redirect was called. From what
I've read, this should not happen and the browser should be sent to
page that was passed in teh Response.Redirect page. The
AutoEventWireup is set to false on all pages. Any help would be
greatly appreciated.
 
J

Joerg Jooss

Thus wrote (e-mail address removed),
I am having an issue when I trigger a Response.Redirect, the Page_Load
fires on the page where the Response.Redirect was called. From what
I've read, this should not happen and the browser should be sent to
page that was passed in teh Response.Redirect page. The
AutoEventWireup is set to false on all pages. Any help would be
greatly appreciated.

Just to clarify... the page, on which you call Response.Redirect() is loaded
*again*?

Cheers,
 
D

dwclark

Yes it is. I can tell this because I put a
System.Diagnostics.Trace.WriteLine(IsPostBack); in the Page_Load body
and whenever the Response.Redirect is called, I receive a True in my
output window and then the next page will load.
 
M

Mark Rae

I am having an issue when I trigger a Response.Redirect, the Page_Load
fires on the page where the Response.Redirect was called. From what
I've read, this should not happen and the browser should be sent to
page that was passed in teh Response.Redirect page. The
AutoEventWireup is set to false on all pages. Any help would be
greatly appreciated.

Let's assume for a second that you've got an <asp:Button> control on a page
with some code behind which includes the Response.Redirect code.

1) Page loads first time - Postback is false - Page_Load fires

2) User clicks the button - page posts back - Postback is true - Page_Load
fires - code behind button executes and does the Response.Redirect

You can't stop the Page_Load event from firing - all you can do is wrap its
contents in a if(Page.IsPostback) {}

The Page_Load event will always fire regardless of what the rest of the code
on that page subsequently does...
 
D

dwclark

Thank you for your explanation, however in my Page_Load section I am
dynamically adding buttons from a query I execute on my database. The
problem is, I do not always get the same button or in the same order (a
feature I want), so when they repopulate, if a new button is in the
place of the old button, I get redirected to the new button destination.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top