Can you set EventArgs from ASP.NET controls?

I have a DropDownList whose SelectedIndexChanged event I set:

move.SelectedIndexChanged += Move;

public void Move(object sender, EventArgs e)

I'd like to create a class derived from EventArgs which is the argument "e" that gets passed to the Move method.

public void Move(object sender, EventArgs e)
  MyEventArgs my_e = (MyEventArgs)e;

  int Id = my_e.ID;
  position = my_e.position;

Is that possible? If it were, I could give this class properties that I could use in the event:

I need to do this as I'd like to pass more information to the Move method than a DropDownList currently contains. I can put this information in the ID of the DropDownList but that is ugly and requires messy string parsing.


ID = "Id_4_position_2"

Note: As requested by Developer Art

I am moving elements in a list. I need to know the old order and the new order. I can do that by using the DropDownList ID to store the old order and SelectedValue to store the new order. So actually, I have all I need but it seems inelegant to put an order in an ID. I also want to avoid custom events, seems too much work.

alt text


That's not possible.

You cannot cast a parent class to a child class.

You mean something like this:

public class MyEventArgs : EventArgs

Then you have EventArgs e and you wish to typecast it to the MyEventArgs. That won't work.

A child class extends the parent class which means it has more meat. The parent class is narrower. There is no sensible way to somehow automatically extend a parent class object to become a child class object.

What if you subclass the UI control and add a custom property to it?

public class PositionDropDownList : DropDownList
    public int Id { get; set; }
    public int Position { get; set; }

You set these values when you generate controls for your form. Then you can get to them in your event:

public void Move(object sender, EventArgs e)
  PositionDropDownList ddl = (PositionDropDownList)sender;

  int Id = ddl.Id;
  position = ddl.Position;

Would something like that work for you?

Need Your Help

Has thread logic changed in ruby2.0 compared to ruby 1.9.3?

ruby multithreading ruby-2.0

I tried an example from "Well Grounded Rubyist" book, which featured Ruby 1.9 in my Ruby 2.0