473,410 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Handler happend after pageload? Is this a valid workaround?

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
Nov 18 '05 #1
2 1286
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
"darrel" <no*****@hotmail.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #2
> 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
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
2
by: Dan Neely | last post by:
Is it possible to override the default behavior and prevent the framework from catching any exceptions leaving these methods and allow the app to handle them elsewhere?
8
by: wASP | last post by:
Hi, I'm having a problem referencing the elements within an object after a method of that object (a member function) has been activated with an onsubmit handler: - - - - - - - - ...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
0
by: joseph conrad | last post by:
Hi, I tried to implement my own session handler in order to keep control on the process the drawback I foun it is not creating and storing in my cookie the PHPSESSID variable anymore. reading te...
1
by: Jim Davis | last post by:
I've been happily using a custom error handler of the following form for a while now: window.onerror = function(Message, URL, Line) { ... } The current case is an intranet application (support...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
0
by: progman417 | last post by:
Hello, I've got a Web User Control containing a gridview with a "select record" button on each row. When the user clicks the button I want to call an event handler in the main page. My...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.