I found "differences between onclick events and oncommand events of buttons in ASP. NET" on the Internet.
Summarized.
From: bytes:
--------------------------------------------------------------
Onclick
<Asp: button id = "button1" commandname = "" commandargument = "" text = "Action 1" runat = "server" onclick = "button#click"/>
Public void button_click (Object sender, eventargs E)
{
String argname = (button) sender). commandname;
// Sender is an object, so commandargument is a string
String argarg = (button) sender). commandargument;
Label1.text = "the action you selected is: <font color = Red>" + argname + "</font>. The action target is: <font color = Red> "+ argarg +" </font> ";
}
<Asp: button id = "button1" commandname = "" commandargument = "" text = "Action 1" runat = "server" oncommand = "button#click"/>
Public void button#click (Object sender, commandeventargs E)
{
String argname = E. commandname;
// Commandeventargsr is a class, so commandargument. tostring ();
String argarg = E. commandargument. tostring ();
Label1.text = "the action you selected is: <font color = Red>" + argname + "</font>. The action target is: <font color = Red> "+ argarg +" </font> ";
}
The. Class commandeventargs has two common attributes: commandname (used to obtain the command name) and commandargument (used to obtain the command parameters ). The two are interrelated.
3. TwoProgramUse onclick and oncommand to stimulate events. The difference is that oncommand is passed with values.
4. All Web controls (such as imagebutton and linkbutton) of the button class contain the commandname and commandargument attributes.
<Asp: button id = "button1" Runar = "server" onclick = "button#click" oncommand = "button#command">
Both onclick and oncommand are defined,
InCodeDefine related events in
Button#click (Object sender, eventargs e ){}
Buttonstmcommand (Object sender, commandeventargs e ){}
1. click the button to trigger the two events at the same time, But click the button first and then Run Command
2. Differences
Command can distinguish different buttons by setting commandname and commandargument,
You can use commandeventargs that contains event data to obtain or set
In click, you can also obtain commandname and commandargument in the form of (button) sender.
Example: onclick
<Asp: button id = "button1" Runar = "server"Onclick = "button#click" Commandname = ""TEXT = "A">
<Asp: button id = "button2" Runar = "server"Onclick = "button#click" Commandname = "B"TEXT = "B">
<Asp: button id = "button3" Runar = "server"Onclick = "button#click" Commandname = "C"TEXT = "C">
Defining a button#click (Object sender, eventargs e) {} is enough,
Other buttons need to be used (button) sender. commandname to determine which button is used.
The oncommand is the same, except for E. commandname.
(Event registration can also be omitted in ASP. net2.0)
3. Both methods are server-side events. To add client events, you must use attributes to set the onclick client events for the button, for example:
Button1.attributes. Add ("onclick", "yourfunction ();")
Define the yourfunction () method in Js.
4. linkbutton has the same features
------------------------------------------------------------------
From: http://www.cnblogs.com/xy6521/articles/1352474.html information is as follows:
<Asp: button id = "button1" Runar = "server" onclick = "button#click" oncommand = "button#command">
Both onclick and oncommand are defined,
Define related events in code
Button#click (Object sender, eventargs e ){}
Buttonstmcommand (Object sender, commandeventargs e ){}
1. click the button to trigger the two events at the same time, But click the button first and then Run Command
2. Differences
Command can distinguish different buttons by setting commandname and commandargument,
You can use commandeventargs that contains event data to obtain or set
In click, you can also obtain commandname and commandargument in the form of (button) sender.
Example: onclick
<Asp: button id = "button1" Runar = "server" onclick = "button#click" commandname = "A" text = "A">
<Asp: button id = "button2" Runar = "server" onclick = "button#click" commandname = "B" text = "B">
<Asp: button id = "button3" Runar = "server" onclick = "button#click" commandname = "C" text = "C">
Defining a button#click (Object sender, eventargs e) {} is enough,
Other buttons need to be used (button) sender. commandname to determine which button is used.
The oncommand is the same, except for E. commandname.
(Event registration can also be omitted in ASP. net2.0)
3. Both methods are server-side events. To add client events, you must use attributes to set the onclick client events for the button, for example:
Button1.attributes. Add ("onclick", "yourfunction ();")
You can also define the yourfunction () method on the ASPX page.