Connecting Tech Pros Worldwide Forums | Help | Site Map

ASP.NET C#: Page_Load executes on post back of other page

Member
 
Join Date: Jan 2008
Posts: 116
#1: Sep 5 '08
Ok..so the title doesnt make much sense. Here is the problem: I have one page, that when loaded checks a session variable to determine that the user is allowed to view the page before sending the contents. On this same page there is a "Log Out" button which is an anchor tag that points back to the login page where it logs out and clears the session.

So now the client is back at the log on page. Clicks log in and the Page_Load event of the page the user came from fires looking for that session variable thus causing an error due to the cleared session which would be initialized on the log in click. WHY!? Were done with that page!

What am I missing here? Why is there a call to the previous page?

nateraaaa's Avatar
Expert
 
Join Date: May 2007
Location: Illinois
Posts: 663
#2: Sep 8 '08

re: ASP.NET C#: Page_Load executes on post back of other page


Posting code would be helpful.

Nathan
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#3: Sep 8 '08

re: ASP.NET C#: Page_Load executes on post back of other page


Quote:

Originally Posted by ShadowLocke


So now the client is back at the log on page. Clicks log in and the Page_Load event of the page the user came from fires looking for that session variable thus causing an error due to the cleared session which would be initialized on the log in click. WHY!? Were done with that page!

I don't understand what you are trying to do.

What is the error you are getting?

Are you by any chance using Server.Transfer?

-Frinny
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Sep 8 '08

re: ASP.NET C#: Page_Load executes on post back of other page


Is the redirection of your "Log Out" button handled on the server side? Or is the button marked as runat="server".
I have seen some odd behavior where the page_load() would get fired because the button is marked as runat="server", even though it's redirecting through javascript and such?
Member
 
Join Date: Jan 2008
Posts: 116
#5: Sep 8 '08

re: ASP.NET C#: Page_Load executes on post back of other page


Quote:

Originally Posted by Plater

Is the redirection of your "Log Out" button handled on the server side? Or is the button marked as runat="server".
I have seen some odd behavior where the page_load() would get fired because the button is marked as runat="server", even though it's redirecting through javascript and such?

The redirect is client side. The runat tag i thought would have been it. But this is the code I had:

[HTML]<a href="Logon.aspx?LOGOUT=LOGOUT">Log out</a>[/HTML]

..Since I was replying i decided to take another look real quick..I think I found the problem. Im sending that logout parameter..so on the postback when your there it logs out before going to the next page....is there a way to clear that on postback? Or should I look for a different way to handle the log out?
Member
 
Join Date: Jan 2008
Posts: 116
#6: Sep 8 '08

re: ASP.NET C#: Page_Load executes on post back of other page


Quote:

Originally Posted by ShadowLocke

The redirect is client side. The runat tag i thought would have been it. But this is the code I had:

[HTML]<a href="Logon.aspx?LOGOUT=LOGOUT">Log out</a>[/HTML]

..Since I was replying i decided to take another look real quick..I think I found the problem. Im sending that logout parameter..so on the postback when your there it logs out before going to the next page....is there a way to clear that on postback? Or should I look for a different way to handle the log out?

First all, thank you all for your replys. I found my problem..when I use the logout/timeout paramater I just added a check for IsPostBack. (in an inherited page I always forget to look into those things..assuming they did it right before i got here)
Reply