ASP.NET Syntax ASP.NET Syntax for Web Controls
Creates a hyperlink-style button on the Web Forms page.
Declarative Syntax
<asp:LinkButton
AccessKey = "string"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
CausesValidation = "True | False"
CommandArgument = "string"
CommandName = "string"
CssClass = "string"
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
Font-Bold = "True | False"
Font-Italic = "True | False"
Font-Names = "string"
Font-Overline = "True | False"
Font-Size = "string | Smaller | Larger | XX-Small | X-Small | Small |
Medium | Large | X-Large | XX-Large"
Font-Strikeout = "True | False"
Font-Underline = "True | False"
ForeColor = "color name | #dddddd"
Height = size
ID = "string"
OnClick = "Click event handler"
OnClientClick = "string"
OnCommand = "Command event handler"
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnUnload = "Unload event handler"
PostBackUrl = "uri"
runat = "server"
SkinID = "string"
Style = "string"
TabIndex = integer
Text = "string"
ToolTip = "string"
ValidationGroup = "string"
Visible = "True | False"
Width = size
/>
NOTE: The content of an <asp:LinkButton
> control can be defined within its opening tag. In this case, you can close the start tag with a trailing slash />
instead of using a separate end tag.
For information on the individual members of this class, see LinkButton in the class library.
The LinkButton control renders a link button on a Web Forms page. You can create either a submit button or a command button.
NOTE: The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. Use the HyperLink control if you want to link to another Web page when the control is clicked.
A submit button does not have a command name associated with the button and simply posts the Web page back to the server. By default, a LinkButton control is a submit button. You can provide an event handler for the Click event to programmatically control the actions performed when the submit button is clicked.
A command button has a command name associated with the button, such as Sort, by setting the CommandName property. This allows you to create multiple LinkButton controls on a Web page and programmatically determine which LinkButton control is clicked. You can also use the CommandArgument property with a command button to provide additional information about the command to perform, such as Ascending. You can provide an event handler for the Command event to programmatically control the actions performed when the command button is clicked.
NOTE: The LinkButton control requires some client-side script support in order to function.
The below code snippet demonstrates how to use a LinkButton control to display a message when the control is clicked.
Within the <head
> of a Web Forms page:
<script language="C#" runat="server">
void LinkButtonClickHandler ( Object sender, EventArgs e ) {
msgLabel.Text = "This text displays when the linkbutton is clicked ...";
}
</script>
<script language="VB" runat="server">
Sub LinkButtonClickHandler ( sender As Object, e As EventArgs )
msgLabel.Text = "This text displays when the linkbutton is clicked ..."
End Sub
</script> |
|
C# |
VB |
Within the <body
> of a Web Forms page:
<form runat=server>
<asp:LinkButton id="LinkButton1" Text = "Click Me"
onClick = "LinkButtonClickHandler" runat="server" />
<p><asp:Label id="msgLabel" runat=server />
</form>
LinkButton Class Button Web Server Controls