LinkButton programming of the WebFrom component of ASP. NET

Source: Internet
Author: User
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 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 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. Assign values to the CommandName and CommandArgument attributes of the LinkButton in the program. Then, through the OnCommand event, you can obtain 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.

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.