Add an event in another event

  • Thread starter Thread starter James P
  • Start date Start date
J

James P

Is it possible to add an event from within another event?

I am having hard time make it work.

Situation:
I have a dropdown. User selects a value and clicks a button.
In the click event of the button, based on some value I need to set the
SelectedIndexChanged event of 2 dropdowns.

The autopost back occurs but the event never gets called.

Why?

Thanks.
James
 
I'm not sure I understand you fully. However, it sounds like what you really
want to do is to execute the same code from 2 different event handlers. That
is, you want to execute the code from one event handler from another event
handler. The best way to do this is to move the code that is executing in
the second event handler to a separate method, and call that method from
both event handlers.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
No. That is not the case. Here is a sample code that could better explain
what I am trying to do.

TextBox txtCondition;
DropDownList ddlLevels;
DropDownList ddlPriorities;
Button btnSearch;

private void btnSearch_Click(object sender, EventArgs e)
{
if (ddlLevels.SelectedItem.Text == "1")
{
ddlPriorities.SelectedIndexChanged += new
EventHandler(this.Priority1handler)
ddlPriorities.AutoPostBack = true;
}
}

private void Priority1handler(object sender, EventArgs e)
{
// Do something.
}

The Auto Post Back works. But the event handler never gets called.

James
 
Back
Top