Commandname and commandargument attributes

Source: Internet
Author: User
Use the commandname and commandargument attributes on the ASP. NET page:

You may be confused about the commandname and commandargument attributes in the linkbutton component. In fact, they play a very important role. Example:

If there are 100 linkbuttons in one of your pages, you need to determine on the server end which is being pressed. Without these two attributes, you can assign values to the text attribute of each linkbutton and check the text attribute value to determine which linkbutton is pressed. Of course, you can also give different names to each linkbutton (of course, you just want the same name, in ASP. net), and then in the event processing function, it checks the sender attribute value to determine which linkbutton is pressed. Although these methods are all feasible, they are not complicated. With the commandname and commandargument attributes, you can easily solve these problems. InProgramAssign values to the commandname and commandargument attributes of the linkbutton. Then, through the oncommand event, you can obtain the data from the commandeventargs class to determine which linkbutton is pressed. So what does the commandeventargs class do? The commandeventargs class stores data related to button events, and can access the data through commandeventargs class attributes in event processing. After a linkbutton is pressed, the data triggered by this linkbutton is stored in the commandeventargs class of the server, accessing the attributes in the commandeventargs class also accesses the pressed linkbutton. In this case, you may still have some questions. Here is a program example to illustrate it.
This article describes how the linkbutton component transmits the commandname and commandargument attribute values through the oncommand () event. And how to read data in the commandeventargs class in the program.
Link. aspx source programCodeAs follows:

<% @ Page Language = "C #" DEBUG = "true" %>
<HTML>
<Head>
<Title> link button component demo </title>
<SCRIPT runat = "server">
Protected void linkbutton_command (Object sender, commandeventargs E)
{
Message. Text = "what you choose:" + E. commandargument;
}
</SCRIPT>
</Head>
<Body>
<Form runat = "server">
<Table cellspacing = 0 cellpadding = 0 border = 1>
<Tr> <TD> select a date: </TD> </tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Monday" runat = "server" commandargument = "Monday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Tuesday" runat = "server" commandargument = "Tuesday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Wednesday" runat = "server" commandargument = "Wednesday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Thursday" runat = "server" commandargument = "Thursday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Friday" runat = "server" commandargument = "Friday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Saturday" runat = "server" commandargument = "Saturday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
<Tr>
<TD align = center>
<Asp: linkbutton text = "Sunday" runat = "server" commandargument = "Sunday" oncommand = "linkbutton_command"/>
</TD>
</Tr>
</Table>
<Asp: Label id = "message" runat = "server"/>
</Form>
</Body>
</Html>

Iv. Summary:

This article describes some important components of the linkbutton component, that is, some important attributes and events. A program example is used to describe how to use it. The emergence of the linkbutton component makes it easier to PASS Parameters on the ASP. NET page. However, this component cannot be used in browsers that do not support the Javascript language because it uses the submit () method in the Javascript language to submit pages.

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.