This documentation is archived and is not being maintained.

LinkButton Web Server Control Declarative Syntax

Creates a hyperlink-style button on a Web Forms page.

    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    ForeColor="color name|#dddddd"
    OnClick="Click event handler"
    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"

Use the LinkButton control to create a hyperlink-style button on a Web Forms page. Specify the text to display in the LinkButton control by either setting the Text property or placing the text between the opening and closing tags of the LinkButton control. You can create either a submit button or a command button.


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.

By setting the CommandName property, you can associate a command name with the command button, such as Sort. 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 addition 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.


The LinkButton control renders JavaScript on the client browser. The client browser must have JavaScript enabled for this control to function properly. For more information on client script, see Client Script in ASP.NET Web Pages By default, page validation is performed when a LinkButton control is clicked. Page validation determines whether the input controls associated with a validation control on the page pass the validation rules specified by the validation control. If you have a LinkButton control that needs to disable this behavior, such as a reset button, set the CausesValidation property to false.

Caution noteCaution:

Text is not HTML encoded before it is displayed in the LinkButton control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.

Command buttons (such as LinkButton controls) are frequently used in templated controls to communicate an action to the parent control. For example, selection in a DataList or changing mode in a FormView.

For detailed information on the LinkButton Web server control's properties and events, see the LinkButton class documentation.

The following example demonstrates how to use a LinkButton control to display a message when the control is clicked.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" >
    <title>LinkButton Example</title>
<script language="C#" runat="server">

      void LinkButton_Click(Object sender, EventArgs e) 
         Label1.Text="You clicked the link button";



   <form id="form1" runat="server">

      <h3>LinkButton Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Click Me" 

      <br />

      <asp:Label id="Label1" runat="server" />