The LinkButton component in the ASP.net WebForm component is also a server-side component that is somewhat similar to the identifier in HTML. Its main function is to display a hyperlink in the ASP.net page. When the link is pressed, the page passes information to the server and handles the corresponding event on the server side.
I. Important components of the LinkButton component:
Let's use this table to illustrate some of the common properties and events of the LinkButton component.
LinkButton组件的常用属性、事件 代表的意思
Text 这是一个属性,就是LinkButton组件显示的文字
CommandName,CommandArgument 这二个属性在功能上基本相同,当Click事件被触发的时候,通过这二个属性可以方便的往服务器端传递数据。对于这二个属性的用法一些重要的用法,在下面有着重的介绍。
OnClick 这个事件是当组件被Click的时候触发
OnCommand 这也是一个事件,并和上面OnClick事件类似,区别在于,这个事件在被触发的时候,往服务器端传递CommandName,CommandArgument属性值。
Two. Take advantage of the CommandName and CommandArgument properties in the asp.net page:
You might be a little confused about the CommandName and CommandArgument attributes in the LinkButton component, and what they do. In fact, they have a very important role. Examples are as follows:
If there are 100 LinkButton in one of your pages, be on the server side to determine which LinkButton is being pressed. Without these two properties, you can assign a value to each LinkButton Text property, and then check the Text property value to determine which LinkButton is being pressed. Of course you can also by giving each LinkButton a different name (of course you just want the same name, in the ASP.net is also not possible), and then in the event handler, by detecting the sender attribute value to determine which LinkButton was pressed. Although these methods are feasible, none of them are trivial. With the CommandName attribute and the CommandArgument attribute, you can easily solve these problems. Assign values to LinkButton's CommandName and CommandArgument properties in your program, and then, through the OnCommand event, you get the data from the CommandEventArgs class. thereby to judge which LinkButton was pressed. So what are the CommandEventArgs? The CommandEventArgs class stores data related to button events and can access the data through the properties of the CommandEventArgs class in event handling. To be clear, when the LinkButton is pressed, the data triggered by this LinkButton is stored in the CommandEventArgs class of the server. Accessing the properties in the CommandEventArgs class also accesses the LinkButton that was pressed. That said, perhaps you are still a little unclear, the following is a procedural example to specify.
Three. Specific usage of LinkButton components:
This article describes how the LinkButton component passes CommandName property values and CommandArgument property values through a OnCommand () event that is associated with a LinkButton component. And how to read the data in the CommandEventArgs class in the program.
The following illustration is the interface that this program is running: