System.Web.UI.WebControls Namespace LinkButton Class
Sets or retrieves the command name associated with the LinkButton control that is passed to the Command event.
Inline |
<asp:linkbutton commandname = strValue ... > |
Script |
LinkButton.CommandName = strValue |
strValue |
String specifying the name of the command to perform when the LinkButton control is clicked. |
The property is read/write with no default value.
Use the CommandName property to specify or determine the command associated with a LinkButton control. This is particularly useful when a Web Forms page include multiple LinkButton controls.
You can set the CommandName property to any valid string that identifies the command to perform when an linkbutton is clicked. You can then programmatically determine the command name of the LinkButton control and handle the command appropriately.
You can also optionally pass additional information about the command by using the CommandArgument property.
The following example demonstrates how to use the CommandName property to create a LinkButton control that sorts a list in ascending order.
<form runat = "server">
<asp:linkbutton id = "myLinkButton" runat = "server"
text = "Sort Ascending"
commandname = "Sort"
commandargument = "Ascending"
onCommand = "getCommandArgs " />
</form>
The below example demontrates a Command event handler that, in this case, simply determines the event arguments passed to the handler when a LinkButton is clicked.
void getCommandArgs ( Object src, CommandEventArgs e ) {
// insert code to sort in ascending order here.
msg.Text = "You clicked the " + e.CommandName +
" - " + e.CommandArgument + " linkbutton.";
}
Sub getCommandArgs ( src As Object, e As CommandEventArgs )
' insert code to sort in ascending order here.
msg.Text = "You clicked the " & e.CommandName & _
" - " & e.CommandArgument & " linkbutton."
End Sub |
|
C# |
VB |
LinkButton Members Command Event