Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Problems with Event Handler


Message #1 by "Hugh McLaughlin" <hugh@k...> on Thu, 9 Jan 2003 18:24:57
Hello Everyone and again, thanks for your help in advance.  This is my 
third post on this problem via other sites.  I am hoping I can 
get some help.  I have an application that can be viewed at:

http://www.hughmclaughlin.com/TimeClock4.aspx

I have posted the code at:

http://www.hughmclaughlin.com/TimeClock.htm

This application is a time clock.  Upon clicking 
the "Clock In" button, it should log the time in and then 
regenerate the employee list, changing the logged in 
employee button to a red "Clocked Out".  Then, when 
the "Clocked Out" button is clicked, the time is logged 
and the button is returned to green and "Clocked In".  I 
have attached the code-behind for the page.  The click 
event is handled by a subroutine called PunchClcok.  For 
some reason, the first click appears to work properly.  
But subsequent clicks require a second click before the 
event executes.  In the example, each time the PucnhClock 
event fires, it writes the event and time at the top of 
the screen.  So this leads me to believe that the event 
handler is never fired since the subroutine is never 
reached (thus the absence of any message).  I am not sure 
why this is not working properly.  

Since the first post, I have recieved responses that the BindData() in 
both the PunchClock and Page_Load are the cause of the problem  However, 
when I take either one out, it still doesn't work.  Also, it was 
suggested that I use a Handles btnPunchClock and to delete the AddHandler 
reference.  However, that seems to completely disconnect the event 
wiring.  Since the BindaData() efeectively rebuilds all of the Handlers 
and CommandArguments, I am not really sure why this would be a problem.  
I am really stuck on this problem.  Any help would be greatly 
appreciated.  

Thanks.
Message #2 by "Peter Lanoie" <planoie@n...> on Thu, 9 Jan 2003 13:44:02 -0500
Hugh,

I looked at your application.  One thing I tried, was I opened it up in two
browsers.  One I used just to refresh the page view.  I performed no actions
on it.  Then in the other browser, I clicked the buttons, one at a time,
refreshing the first browser between each button click.  I do see the same
problem, of having to click on the button twice in some cases to get it to
go.

I have experienced similar problems, and have found various things that
contributed to them.  One issue is page execution order.  What I'm thinking
is happening is this:

1. Page draws with all people "clocked out", thus the green "Clock In"
button.
2. You click a button, page posts.
3. Page postback execution:
	3a. Page draws. This happens from the page_load, you call "BindData()"
	3b. The page handles the events.

I think what's going on is that the event gets picked up after the page is
redrawn and you are seeing a one click "delay" in the browser.  This will
cause all kinds of problems.  I file this kind of problem under the
category, "Ok, .Net is cool and all with it's whiz-bang postback stuff, but
how do I do anything USEFUL with it??"

One resolution I have found, which I really dislike, but in an effort to
accomplish anything have had to resort to is the use of the onPreRender and
Render routines.  These get called after your events so if you draw your
controls in these routines, presumably, they'll take on the appropriate
characteristics governed by their respective data.  That is one possibility.

The second involves modifying the acted upon control in the event.  If the
page draws the controls, then your event fires, but the event only modifies
the data affecting the control, since the control is already drawn, you get
the discrepancy.  If your event also modifies the control itself, you should
be able to keep them in sync.  The harder part in this is of course "getting
at" the control.  If you can ID the controls when you draw them out in
BindData(), you might be able to do this.  If you IDed them based on some
base name "ClockAction_" then tack on unique information, like a row ID or
something like that, then theoretically you could be able to reference that
control from the event handler by the name you've provided.

I hope that answers your question.  This problem has been a thorn in my side
for some time.  It's been a terrible battle to win, and yet, I'm not
convinced it was such a great victory.  I'm very curious to hear other's
input to your problem or also to my suggestions.  There is most likely a
much more elegant way then what I've proposed.

Peter

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Thursday, January 09, 2003 18:25
To: ASP.NET
Subject: [aspx] Problems with Event Handler


Hello Everyone and again, thanks for your help in advance.  This is my
third post on this problem via other sites.  I am hoping I can
get some help.  I have an application that can be viewed at:

http://www.hughmclaughlin.com/TimeClock4.aspx

I have posted the code at:

http://www.hughmclaughlin.com/TimeClock.htm

This application is a time clock.  Upon clicking
the "Clock In" button, it should log the time in and then
regenerate the employee list, changing the logged in
employee button to a red "Clocked Out".  Then, when
the "Clocked Out" button is clicked, the time is logged
and the button is returned to green and "Clocked In".  I
have attached the code-behind for the page.  The click
event is handled by a subroutine called PunchClcok.  For
some reason, the first click appears to work properly.
But subsequent clicks require a second click before the
event executes.  In the example, each time the PucnhClock
event fires, it writes the event and time at the top of
the screen.  So this leads me to believe that the event
handler is never fired since the subroutine is never
reached (thus the absence of any message).  I am not sure
why this is not working properly.

Since the first post, I have recieved responses that the BindData() in
both the PunchClock and Page_Load are the cause of the problem  However,
when I take either one out, it still doesn't work.  Also, it was
suggested that I use a Handles btnPunchClock and to delete the AddHandler
reference.  However, that seems to completely disconnect the event
wiring.  Since the BindaData() efeectively rebuilds all of the Handlers
and CommandArguments, I am not really sure why this would be a problem.
I am really stuck on this problem.  Any help would be greatly
appreciated.

Thanks.

Message #3 by "Hugh McLaughlin" <hugh@k...> on Thu, 9 Jan 2003 19:22:00
Well I have to agree with you about the .Net stuff.  If I can't get this 
working soon, I will throw together a simple ASP page, because this would 
be a snap in classic ASP (makes me wonder why I am trying this on .Net)

I will try your idea, however, I would think that the BindaData() routine, 
being in both spots would cover all of this since the PuchClock subroutine 
actaully logs to the database.  So the refresh in the Page_Load or 
PunchClock routines simply read the data already in the table.  Thus, the 
refresh updates the buttons, since the page displays properly after a 
refresh (on the Page_Load should have fired).

HELP!!!!!! 
> Hugh,

I looked at your application.  One thing I tried, was I opened it up in two
browsers.  One I used just to refresh the page view.  I performed no 
actions
on it.  Then in the other browser, I clicked the buttons, one at a time,
refreshing the first browser between each button click.  I do see the same
problem, of having to click on the button twice in some cases to get it to
go.

I have experienced similar problems, and have found various things that
contributed to them.  One issue is page execution order.  What I'm thinking
is happening is this:

1. Page draws with all people "clocked out", thus the green "Clock In"
button.
2. You click a button, page posts.
3. Page postback execution:
	3a. Page draws. This happens from the page_load, you call "BindData
()"
	3b. The page handles the events.

I think what's going on is that the event gets picked up after the page is
redrawn and you are seeing a one click "delay" in the browser.  This will
cause all kinds of problems.  I file this kind of problem under the
category, "Ok, .Net is cool and all with it's whiz-bang postback stuff, but
how do I do anything USEFUL with it??"

One resolution I have found, which I really dislike, but in an effort to
accomplish anything have had to resort to is the use of the onPreRender and
Render routines.  These get called after your events so if you draw your
controls in these routines, presumably, they'll take on the appropriate
characteristics governed by their respective data.  That is one 
possibility.

The second involves modifying the acted upon control in the event.  If the
page draws the controls, then your event fires, but the event only modifies
the data affecting the control, since the control is already drawn, you get
the discrepancy.  If your event also modifies the control itself, you 
should
be able to keep them in sync.  The harder part in this is of 
course "getting
at" the control.  If you can ID the controls when you draw them out in
BindData(), you might be able to do this.  If you IDed them based on some
base name "ClockAction_" then tack on unique information, like a row ID or
something like that, then theoretically you could be able to reference that
control from the event handler by the name you've provided.

I hope that answers your question.  This problem has been a thorn in my 
side
for some time.  It's been a terrible battle to win, and yet, I'm not
convinced it was such a great victory.  I'm very curious to hear other's
input to your problem or also to my suggestions.  There is most likely a
much more elegant way then what I've proposed.

Peter

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Thursday, January 09, 2003 18:25
To: ASP.NET
Subject: [aspx] Problems with Event Handler


Hello Everyone and again, thanks for your help in advance.  This is my
third post on this problem via other sites.  I am hoping I can
get some help.  I have an application that can be viewed at:

http://www.hughmclaughlin.com/TimeClock4.aspx

I have posted the code at:

http://www.hughmclaughlin.com/TimeClock.htm

This application is a time clock.  Upon clicking
the "Clock In" button, it should log the time in and then
regenerate the employee list, changing the logged in
employee button to a red "Clocked Out".  Then, when
the "Clocked Out" button is clicked, the time is logged
and the button is returned to green and "Clocked In".  I
have attached the code-behind for the page.  The click
event is handled by a subroutine called PunchClcok.  For
some reason, the first click appears to work properly.
But subsequent clicks require a second click before the
event executes.  In the example, each time the PucnhClock
event fires, it writes the event and time at the top of
the screen.  So this leads me to believe that the event
handler is never fired since the subroutine is never
reached (thus the absence of any message).  I am not sure
why this is not working properly.

Since the first post, I have recieved responses that the BindData() in
both the PunchClock and Page_Load are the cause of the problem  However,
when I take either one out, it still doesn't work.  Also, it was
suggested that I use a Handles btnPunchClock and to delete the AddHandler
reference.  However, that seems to completely disconnect the event
wiring.  Since the BindaData() efeectively rebuilds all of the Handlers
and CommandArguments, I am not really sure why this would be a problem.
I am really stuck on this problem.  Any help would be greatly
appreciated.

Thanks.

Message #4 by "Peter Lanoie" <planoie@n...> on Thu, 9 Jan 2003 14:25:16 -0500
Hugh,

Sorry, my bad.  I didn't notice the call to BindData in the event handler
that you so helpfully mention at least 4 times in your posts.  Doh'.  What
you said would seem to make sense to me too.  It should take care of things.
One problem I have noticed that can be problematic also, depending on how
you are doing things, the viewstate really mucks things up.  I had a page
that was loading HTML that was not being used by .Net at all. I was dealing
with it in a totally classic ASP way, but the viewstate, being that it
maintains the state of everything in the page, was causing values to change
back or not change.  I disabled viewstate on some things and it cleared up.
Given that you are drawing things from the database every time, you may be
able to fix it by disabling viewstate on either those buttons or the whole
form (I can heard the silent cringe from some of you folks right now... :).

Play around with the viewstate and let us know how you fair.

Peter

-----Original Message-----

Well I have to agree with you about the .Net stuff.  If I can't get this
working soon, I will throw together a simple ASP page, because this would
be a snap in classic ASP (makes me wonder why I am trying this on .Net)

I will try your idea, however, I would think that the BindaData() routine,
being in both spots would cover all of this since the PuchClock subroutine
actaully logs to the database.  So the refresh in the Page_Load or
PunchClock routines simply read the data already in the table.  Thus, the
refresh updates the buttons, since the page displays properly after a
refresh (on the Page_Load should have fired).

HELP!!!!!!
> Hugh,

I looked at your application.  One thing I tried, was I opened it up in two
browsers.  One I used just to refresh the page view.  I performed no
actions
on it.  Then in the other browser, I clicked the buttons, one at a time,
refreshing the first browser between each button click.  I do see the same
problem, of having to click on the button twice in some cases to get it to
go.

I have experienced similar problems, and have found various things that
contributed to them.  One issue is page execution order.  What I'm thinking
is happening is this:

1. Page draws with all people "clocked out", thus the green "Clock In"
button.
2. You click a button, page posts.
3. Page postback execution:
	3a. Page draws. This happens from the page_load, you call "BindData
()"
	3b. The page handles the events.

I think what's going on is that the event gets picked up after the page is
redrawn and you are seeing a one click "delay" in the browser.  This will
cause all kinds of problems.  I file this kind of problem under the
category, "Ok, .Net is cool and all with it's whiz-bang postback stuff, but
how do I do anything USEFUL with it??"

One resolution I have found, which I really dislike, but in an effort to
accomplish anything have had to resort to is the use of the onPreRender and
Render routines.  These get called after your events so if you draw your
controls in these routines, presumably, they'll take on the appropriate
characteristics governed by their respective data.  That is one
possibility.

The second involves modifying the acted upon control in the event.  If the
page draws the controls, then your event fires, but the event only modifies
the data affecting the control, since the control is already drawn, you get
the discrepancy.  If your event also modifies the control itself, you
should
be able to keep them in sync.  The harder part in this is of
course "getting
at" the control.  If you can ID the controls when you draw them out in
BindData(), you might be able to do this.  If you IDed them based on some
base name "ClockAction_" then tack on unique information, like a row ID or
something like that, then theoretically you could be able to reference that
control from the event handler by the name you've provided.

I hope that answers your question.  This problem has been a thorn in my
side
for some time.  It's been a terrible battle to win, and yet, I'm not
convinced it was such a great victory.  I'm very curious to hear other's
input to your problem or also to my suggestions.  There is most likely a
much more elegant way then what I've proposed.

Peter

-----Original Message-----

Hello Everyone and again, thanks for your help in advance.  This is my
third post on this problem via other sites.  I am hoping I can
get some help.  I have an application that can be viewed at:

http://www.hughmclaughlin.com/TimeClock4.aspx

I have posted the code at:

http://www.hughmclaughlin.com/TimeClock.htm

This application is a time clock.  Upon clicking
the "Clock In" button, it should log the time in and then
regenerate the employee list, changing the logged in
employee button to a red "Clocked Out".  Then, when
the "Clocked Out" button is clicked, the time is logged
and the button is returned to green and "Clocked In".  I
have attached the code-behind for the page.  The click
event is handled by a subroutine called PunchClcok.  For
some reason, the first click appears to work properly.
But subsequent clicks require a second click before the
event executes.  In the example, each time the PucnhClock
event fires, it writes the event and time at the top of
the screen.  So this leads me to believe that the event
handler is never fired since the subroutine is never
reached (thus the absence of any message).  I am not sure
why this is not working properly.

Since the first post, I have recieved responses that the BindData() in
both the PunchClock and Page_Load are the cause of the problem  However,
when I take either one out, it still doesn't work.  Also, it was
suggested that I use a Handles btnPunchClock and to delete the AddHandler
reference.  However, that seems to completely disconnect the event
wiring.  Since the BindaData() efeectively rebuilds all of the Handlers
and CommandArguments, I am not really sure why this would be a problem.
I am really stuck on this problem.  Any help would be greatly
appreciated.

Thanks.


  Return to Index