Handler happend after pageload? Is this a valid workaround?

D

darrel

The scenario:

I have a button that when clicked sets a cookie value.

On page load, I read this cookie value and write out some specific HTML.

The catch:

It appears that the buttonHandler executes AFTER the page load on the
postback.

As such, my page is 'one refresh' behind. In otherwords, If I hit the button
to set the cookie, when the page loads, it hasn't 'taken' the new setting
yet since it loaded before the cookie was set.

To get around this, after setting the value in the button handler, I then
response.redirect back to itself. Is this the best way to handle this
problem, or is there a better way to go about this? This method seems to
work just fine, but I'm not sure if I'm committing some huge .net faux pau.


-Darrel
 
T

Travis Murray

You would be much better off just reading the cookie in your button click
event handler (which, as you note, runs after the page_load). It sure beats
making an extra round-trip to the server.

Travis Murray
MCSD, MCT
Artiem Consulting, Inc.
http://www.artiem.com
 
D

darrel

You would be much better off just reading the cookie in your button click
event handler (which, as you note, runs after the page_load). It sure beats
making an extra round-trip to the server.

Oh. Duh. Yea, that makes sense!

That said, I don't think a response.redirect is a return to the server, is
it? From what I can tell, the redirect happens on the server end since it
happens before the page is fully rendered to be sent back to the browser. I
could be wrong about that, though.

-Darrel
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top