Is this a bug?

Discussion in 'ASP .Net' started by Mark Rae, Feb 5, 2006.

  1. Mark Rae

    Mark Rae Guest

    This behaviour has existed since v1.x, and it's still there in v2, so I
    wonder if it is actually a bug or a "feature" :) If the latter, I can't see
    the rationale behind it...

    Here's how to reproduce it.

    1) Create a simple web page with an <asp:DropDownList> and an <asp:Button>

    2) Create a SelectedIndexChanged method for the DropDownList and a Command
    event for the Button

    3) Add any single line of code to each event - just enough so you can set a
    breakpoint

    4) Populate the DropDownList in the Page_Init method - only a couple of
    items will do, just enough to cause the event to fire.

    5) Set a breakpoint in the SelectedIndexChanged method and the Command
    method

    6) Run the page in Debug mode

    7) Select a different item in the DropDownList - you jump into its
    SelectedIndexChanged method as expected - hit F5 to resume

    8) Click the Button - you jump into the DropDownList's SelectedIndexChanged
    method before jumping into the Button's Command method - that's bad, at
    least, to my way of thinking. I would have expected the Page_Init to fire,
    the Page_Load to fire and the Button's Command method to fire. I would have
    expected the ViewState to remember the DropDownList's selection, but not its
    SelectedIndexChanged method to fire.

    Can anyone please confirm that this is a bug?
     
    Mark Rae, Feb 5, 2006
    #1
    1. Advertisements

  2. Mark Rae

    Mark Rae Guest

    I should point out that there is an extremely simple workaround for this...

    E.g. if the DropDownList is called cmbShipping:

    public void cmbShipping_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (Request.Form["__EVENTTARGET"] == "cmbShipping")
    {
    // rest of the method's code goes here
    }
    }
     
    Mark Rae, Feb 5, 2006
    #2
    1. Advertisements

  3. Kevin Spencer, Feb 5, 2006
    #3
  4. Mark Rae

    Mark Rae Guest

    So, the user clicks an <asp:Button> - which phase causes the
    SelectIndexChanged method of a completely different control to fire?
     
    Mark Rae, Feb 5, 2006
    #4
  5. Heck, Mark, I don't know. I didn't write the app.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Who is Mighty Abbott?
    A twin turret scalawag.
     
    Kevin Spencer, Feb 6, 2006
    #5
  6. Mark Rae

    Mark Rae Guest

    Kevin,
    ???

    With the greatest of respect, I don't think you read my initial post. This
    is not a problem with a particular app - it's generic...

    If you go through the steps I outline and click on the button, the code
    behind the DropDownList fires first... This can't be correct behaviour...
     
    Mark Rae, Feb 6, 2006
    #6
  7. Hi Mark,
    The behavior is as the object model is designed. As I said, it's a complex
    object model, and event timing is always tricky. Check out the reference I
    posted.

    Whether the object model is "correct" or not is a purely subjective point of
    view, although Microsoft certainly does take note of comments like yours
    when they design their software. They want to please as many potential
    customers as possible, since that is how you get business. In fact, they
    have specific web sites where you can make suggestions about the software,
    and they pay a great deal of attention to those suggestions. So, don't think
    that complaining is of no avail whatsoever. Whenever you feel something is
    not behaving as it should, please feel free to post your comments!

    But in the meantime, you need to go with the current flow, as you can't
    change it (any time soon).

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Who is Mighty Abbott?
    A twin turret scalawag.
     
    Kevin Spencer, Feb 6, 2006
    #7
  8. Mark Rae

    Mark Rae Guest

    I did - that's why I replied...
    I still don't get why this behaviour is a "good thing", though...

    I understand that the Page_xxxx events must always fire, but the link you
    advised me to refer to pretty much CONFIRMS that this behaviour is wrong!

    Answer me this:

    Imagine you have two <asp:Button> controls on the same page, each with a
    separate Command event. You click one of them - would you expect the other
    one's Command event to fire?
    Like I said, there's a very simple workaround...
     
    Mark Rae, Feb 6, 2006
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.