I am calling a method from an event in a webcontrol, this event passes the sender object, which I want to use.
I want to take the sender object, in whatever form it is, say a button or linkbutton, and put it into a reference.
As I first set out to write this code: I check the type of the object, and depending on what type it is, I cast that type into my var for holding, only problem is, oh yeah it's out of scope when I leave my statement block, and I don't know the type beforehand to define it directly in the method.
How do I define a reference to the sender object, cast to the correct type, that is accessible from within my event method (in the case below "submitForm") without knowing the type of the sender beforehand?
protected void submitForm(object sender, System.EventArgs e)
if ( sender.GetType().Name.ToString() == "Button")
Button submitter = (Button)sender;
else if ( sender.GetType().Name.ToString() == "LinkButton")
LinkButton submitter = (LinkButton)sender;
// submitter reference not available