Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Event handlers called twice, or not at all (http://www.velocityreviews.com/forums/t757141-event-handlers-called-twice-or-not-at-all.html)

Andy Baldwin 10-14-2004 07:28 AM

Event handlers called twice, or not at all
 
Ok, sorry for the long post in advance, but I need an expert opinion
here. I have already crawled through the groups via google and
additionally asked everyone that I can find in Yahoo's chat for
programmers and web designers.

Here is the issue in a nutshell, I am having a situation where my
event handlers are firing twice, or not at all. We need some
background here, because I am going about things very different from
traditional ASP.Net development. Most of the tutorials, articles and
books that I have read have rarely gone over how to programatically
create your own web controls, much less to the extent that I am doing
it. I am basically making a way that all of my (custom composite) web
controls are created for me dynamically based off of info gathered
from SQL Server and some of my own tables that contain metadata about
the DB in question. This being said, I have a "Form" object that
implements placeholder. When you construct this object (in the
simplest way), you pass in a table name and an optional record ID.
With this information I gladly create a form, including dropdowns for
secondary table lookups and calendar controls (that default to
hidden). Lets take the calendar control for an example. My composite
calendar control has 3 controls in all actuality. A text box that
allows the user to type in a date, a button to hide and show the
calendar control, and the calendar control itself. There are two
events associated with this control, the onclick event for the button
hides and shows the associated calendar, and the dateChange event (I
think thats what it is called) puts the selected date into the
textbox. Now that we know this, let me tell you since the eventhandler
for hide/show is called two times, it is never shown (It shows it,
then hides it in a split second). IF I say "if its not a postback,
show the form", then the event is never fired, because on postback,
the button, much less than it's event do not exist. In essence, when I
click the button, it first fires the page_load event, then either:

1) If I always generate the form, calls the button click event two
times
2) If I only generate the form on a non postback, then never fires the
event because the button was never re-generated in the postback.

After saying this, I realize that somehow the events are not being
persisted as needing to be executed regardless of if the original
button even exists or not, Is this indeed the case?

There is hope yet. I have an older version of the code that did work
correctly, but I have done some major refactoring, combining
appropriate code into the appropriate class files (got rid of a few
files that way, and it makes a lot more sense now). You can find a
diagram of how it used to be and how it is now here:

http://www17.brinkster.com/multiform...es/handler.gif

Hopefully this will jog someones memory

So, so far I have tried these things:

1) Flip flopped the AutoEventWireUp field in the page directives.
2) Set "EnableViewState" on the placeholder that contains the form to
true (although I read that this defaults to true anyways).
3) Stepped through my code a hundred times, I am only adding the event
handler once, and I even remove the same event handler before I add it
again. If it was a case of the event handlers being re-added over and
over again to the same control, I would have to assume that every time
I click the button it would add one to the number of times that the
event fires, but not only is that not the case.
4) There is nothing in the stack trace between calls to the event
handlers, so the CLR MUST be calling it two times, and I am not
accidentally calling the handler explicitly
5) Did Global searches for the calendar class and other similar
variables, the ones that are used are all correct.
6) Looked at quite a few other associated events and they have the
same problem.


I realize my next steps are:

1) Slowly roll back the code to it's previous version to figure out
the deal (this would take a day or two, then I would have to add all
that stuff in again.
2) Look for a hack that works (although I thought that remkoving the
event handler before adding it again, was a hack.
3) Reinstall the .Net framework and hope this is a fluke (although I
am pretty sure I have the latest version.

But I am hoping that someone here can help out.

Again this worked with an older, version of the code, but no more.

PLEASE Help!

AB

vbMental 10-29-2004 12:49 AM

RE: Event handlers called twice, or not at all
 
First let me say I feel your pain. I am struggling with a similar situation.
Maybe we can help each other. I think it lies in understanding the order of
events and interaction of the page and controls.
Right now I'm have usercontrols inside of user controls and the events get
out of wack also.

I got kind of lost in your detail though, let me if you have figured it out
yet.

"Andy Baldwin" wrote:

> Ok, sorry for the long post in advance, but I need an expert opinion
> here. I have already crawled through the groups via google and
> additionally asked everyone that I can find in Yahoo's chat for
> programmers and web designers.
>
> Here is the issue in a nutshell, I am having a situation where my
> event handlers are firing twice, or not at all. We need some
> background here, because I am going about things very different from
> traditional ASP.Net development. Most of the tutorials, articles and
> books that I have read have rarely gone over how to programatically
> create your own web controls, much less to the extent that I am doing
> it. I am basically making a way that all of my (custom composite) web
> controls are created for me dynamically based off of info gathered
> from SQL Server and some of my own tables that contain metadata about
> the DB in question. This being said, I have a "Form" object that
> implements placeholder. When you construct this object (in the
> simplest way), you pass in a table name and an optional record ID.
> With this information I gladly create a form, including dropdowns for
> secondary table lookups and calendar controls (that default to
> hidden). Lets take the calendar control for an example. My composite
> calendar control has 3 controls in all actuality. A text box that
> allows the user to type in a date, a button to hide and show the
> calendar control, and the calendar control itself. There are two
> events associated with this control, the onclick event for the button
> hides and shows the associated calendar, and the dateChange event (I
> think thats what it is called) puts the selected date into the
> textbox. Now that we know this, let me tell you since the eventhandler
> for hide/show is called two times, it is never shown (It shows it,
> then hides it in a split second). IF I say "if its not a postback,
> show the form", then the event is never fired, because on postback,
> the button, much less than it's event do not exist. In essence, when I
> click the button, it first fires the page_load event, then either:
>
> 1) If I always generate the form, calls the button click event two
> times
> 2) If I only generate the form on a non postback, then never fires the
> event because the button was never re-generated in the postback.
>
> After saying this, I realize that somehow the events are not being
> persisted as needing to be executed regardless of if the original
> button even exists or not, Is this indeed the case?
>
> There is hope yet. I have an older version of the code that did work
> correctly, but I have done some major refactoring, combining
> appropriate code into the appropriate class files (got rid of a few
> files that way, and it makes a lot more sense now). You can find a
> diagram of how it used to be and how it is now here:
>
> http://www17.brinkster.com/multiform...es/handler.gif
>
> Hopefully this will jog someones memory
>
> So, so far I have tried these things:
>
> 1) Flip flopped the AutoEventWireUp field in the page directives.
> 2) Set "EnableViewState" on the placeholder that contains the form to
> true (although I read that this defaults to true anyways).
> 3) Stepped through my code a hundred times, I am only adding the event
> handler once, and I even remove the same event handler before I add it
> again. If it was a case of the event handlers being re-added over and
> over again to the same control, I would have to assume that every time
> I click the button it would add one to the number of times that the
> event fires, but not only is that not the case.
> 4) There is nothing in the stack trace between calls to the event
> handlers, so the CLR MUST be calling it two times, and I am not
> accidentally calling the handler explicitly
> 5) Did Global searches for the calendar class and other similar
> variables, the ones that are used are all correct.
> 6) Looked at quite a few other associated events and they have the
> same problem.
>
>
> I realize my next steps are:
>
> 1) Slowly roll back the code to it's previous version to figure out
> the deal (this would take a day or two, then I would have to add all
> that stuff in again.
> 2) Look for a hack that works (although I thought that remkoving the
> event handler before adding it again, was a hack.
> 3) Reinstall the .Net framework and hope this is a fluke (although I
> am pretty sure I have the latest version.
>
> But I am hoping that someone here can help out.
>
> Again this worked with an older, version of the code, but no more.
>
> PLEASE Help!
>
> AB
>



All times are GMT. The time now is 08:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.