Conversion between onclick and oncommand

Source: Internet
Author: User

From http://www.cnblogs.com/BluceLee/

"

<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 = "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">
Define 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.

"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.