Event handlers called twice, or not at all

Discussion in 'ASP .Net Building Controls' started by Andy Baldwin, Oct 14, 2004.

  1. Andy Baldwin

    Andy Baldwin Guest

    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/multiformity/images/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
     
    Andy Baldwin, Oct 14, 2004
    #1
    1. Advertising

  2. Andy Baldwin

    vbMental Guest

    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/multiformity/images/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, Oct 29, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward Bills
    Replies:
    0
    Views:
    460
    Edward Bills
    Aug 25, 2004
  2. Mike Hofer

    Server-side event handlers firing twice

    Mike Hofer, Mar 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    465
    Mike Hofer
    Mar 14, 2006
  3. S_K
    Replies:
    6
    Views:
    1,209
    Robert Dunlop
    Nov 8, 2007
  4. Andy Baldwin

    Event handlers called twice, or not at all

    Andy Baldwin, Oct 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    290
    vbMental
    Oct 29, 2004
  5. Martha Vineyard

    Safari related ? event handlers not being called

    Martha Vineyard, Dec 16, 2003, in forum: Javascript
    Replies:
    1
    Views:
    143
    Martin Honnen
    Dec 16, 2003
Loading...

Share This Page