Is there a way to know what parameters are needed by an event in Visual Studio 2010?
Let's say I have a DropDownList control and I want to bind a method to the "OnSelectedIndexChanged", I would do something like this
In the ASPX File:
<asp:DropDownList ID="lstMyList" runat="server" OnSelectedIndexChanged="lstMyList_SelectedIndexChanged"></asp:DropDownList>
In the codebehind:
protected void lstMyList_SelectedIndexChanged(object sender, EventArgs e)
{
...
}
Is there a way to know what parameters the method needs? (In this case, an object for the sender and an EventArgs parameter for the event.)
I know you can easily create the method by double-clicking the right event in Design Mode, but it does a mess with your code so I prefer not to use it.
Thanks!
To access properties on the solution, right click the solution node in Solution Explorer and choose Properties.
F5 & Ctrl-F5 F5 is used to start your project in debug mode and Ctrl-F5 is used to start your project without debug mode.
New! Save questions or answers and organize your favorite content.
Hover over a variable to see its value. The most commonly used way to look at variables is the DataTip. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable.
You can find out the parameters by "going to definition" (F12) on the appropriate event, finding out what delegate type it uses, then going to definition on that. In this case the SelectedIndexChanged event has type EventHandler which is defined as follows:
[SerializableAttribute]
[ComVisibleAttribute(true)]
public delegate void EventHandler(
Object sender,
EventArgs e
)
You can also find this information by searching the web or pressing F1 and searching in the help.
I know you can easily create the method by double-clicking the right event in Design Mode, but it does a mess with your code so I prefer not to use it.
I think you should try to overcome your fear of using the designer. You are most likely wasting more time in lost productivity by not using the code generation features in Visual Studio than the potential time you might have saved by protecting yourself against the designer messing up your code.
Hardly economical in terms of keystrokes and productivity but a possibility, if you're finding the event in code to 'Go To Definition' anyway, and imagining for a moment that you don't mind using the code editor features of VS, too, is to hit the Tab key, then add the += before hitting the Tab key another two times. This will generate the appropriate delegation and method definition, which will result in you seeing the method signature.
For instance, typing the following, tabbing appropriately (twice after typing '+='):
MyType.MyEvent += new System.EventHandler(MyType_MyEvent);
Generates a method like the following:
void MyType_MyEvent(object sender, EventArgs e)
{
throw new NotImplementedException();
}
Now, the productivity reduction could occur if you don't actually require both pieces of code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With