Is this a bug?

M

Mark Rae

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?
 
M

Mark Rae

Can anyone please confirm that this is a bug?

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
}
}
 
K

Kevin Spencer

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.
 
M

Mark Rae

Kevin,
Heck, Mark, I don't know. I didn't write the app.

???

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...
 
K

Kevin Spencer

Hi Mark,
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...

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.
 
M

Mark Rae

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.

I did - that's why I replied...
Whenever you feel something is not behaving as it should, please feel free
to post your comments!

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?
But in the meantime, you need to go with the current flow, as you can't
change it (any time soon).

Like I said, there's a very simple workaround...
 

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

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top