Command Name Property + Button
Code:
protected void Button1_Command(object sender, CommandEventArgs e)
{
}
Code:
protected void Button1_Click(object sender, EventArgs e)
{
}
Whats the difference between above two lines of code???
I read that you can write all the button click events code in one button command event??
But Even we can assign button click event to more than one Button.???
When we use Command Name event????
Re: Command Name Property + Button
Hey,
The difference between the two is that one accepts a parameter of EventsArgs, and the other contains CommandEventArgs. These are two very different things, and they will provide very different properties.
You can easily create one event handler, that handles the click event of multiple buttons.
You would do this as follows:
1) Create the event handler:
Code:
protected void CommonButtonClick(object sender, EventArgs e)
{
}
2) Hook up the various button click events to use this event.
You can see how this can be achieved here:
http://www.vbforums.com/showthread.p...95#post3643595
In post #7.
Hope that helps!!
Gary
Re: Command Name Property + Button
Hey Gary, I read your link and am amazed that after quite a few years using VS I have never clicked the "yellow lighting bolt" to view control events in the properties window. How didn't I know it was there...... I look at that window countless hours a week.
Re: Command Name Property + Button
Ha ha, it is one of those features that is quite often overlooked. Especially if you come from a VB background. In VB, you have the option of selecting events directly in the code view, but you can't do this in C#. Although the yellow bolt also exists in VB.Net land, it is the only interface that C# has.
Gary
Re: Command Name Property + Button
Ah VB land can become a little too comfortable after a while. Thanks for your insight.:)
Re: Command Name Property + Button
I guess I had the benefit of starting in VB, and then transferring over to C# in my most recent job, so I have to converse in both languages, so I have picked up a few things along the way.
Gary
Re: Command Name Property + Button
hi Gep13, I know that we bind multiple buttons to a single event handler,we can also bind the multiple buttons to a single command event.Can you give me example where command event is used? I dont think so it of any use?
Re: Command Name Property + Button
Hey,
As per the documentation:
http://msdn.microsoft.com/en-us/libr...n.command.aspx
You would use the Command event handler, when there is a CommandName associated with the button.
Gary