What is ASP. NET LinkButton component programming? First, let's take a look:
The LinkButton component in the WebForm component of ASP. NET is also A server component, which is somewhat similar to the <A> identifier in HTML. Its main function is to display a hyperlink on the ASP. NET page. When the link is pressed, the page will transmit information to the server and process the corresponding events on the server.
I. important components of the ASP. NET LinkButton component:
The following table describes some common attributes and events of the LinkButton component.
Common attributes and events of the LinkButton component
Text is an attribute, that is, the Text displayed by the LinkButton component.
CommandName and CommandArgument have the same functions. When a Click event is triggered, the two attributes can be used to conveniently transmit data to the server. Some important usage of these two attributes are described below.
OnClick is triggered when the component is clicked.
OnCommand is also an event and similar to the above OnClick event. The difference is that when this event is triggered, the CommandName and CommandArgument attribute values are passed to the server.
2. Use the CommandName and CommandArgument attributes on the ASP. NET page:
You may be confused about the CommandName and CommandArgument attributes in the ASP. NET LinkButton component. In fact, they play a very important role. Example:
If there are 100 ASP. NET linkbuttons in one of your pages, you need to determine which LinkButton is being pressed on the server side. 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.
Assign values to the CommandName and CommandArgument attributes of LinkButton in the program. Then, through the OnCommand event, you can obtain data from the CommandEventArgs class to determine which ASP is used. NET 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.
Iii. usage of the ASP. NET LinkButton component:
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.
Is the interface for running the program:
The source code of Link. aspx is as follows:
- <%@ Page Language ="C #"Debug ="True"%>
- <Html>
- <Head>
- <Title> Link Button component demo program </title>
- <Script runat ="Server">
- Protected VoidLinkButton_Command (ObjectSender, CommandEventArgs e)
- {
- Message. Text ="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. ASP. NET LinkButton component programming 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.
This section describes the programming of ASP. NET LinkButton components. It is helpful for you to learn ASP. NET LinkButton component programming.
- Analysis on Transmission Mechanism of ASP. NET Component Design
- Analysis on complex attributes and status management of ASP. NET Component Design
- Analysis of ASP. NET httpHandler
- Programming of ASP. NET components
- Programming analysis of ASP. NET CheckBoxList component