Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
LinkButton Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
LinkButton Class

Displays a hyperlink-style button control on a Web page.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class LinkButton _
    Inherits WebControl _
    Implements IButtonControl, IPostBackEventHandler
Visual Basic (Usage)
Dim instance As LinkButton
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class LinkButton : WebControl, IButtonControl, 
    IPostBackEventHandler
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class LinkButton : public WebControl, 
    IButtonControl, IPostBackEventHandler
JScript
public class LinkButton extends WebControl implements IButtonControl, IPostBackEventHandler
ASP.NET
<asp:LinkButton />

Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.

NoteNote:

The LinkButton control renders JavaScript to 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.

You can create either a Submit button or a Command button. A Submit button does not have a command name associated with it. The button 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. On the other hand, a Command button has a command name associated with the button, such as Sort. Set the CommandName property to specify the command name. 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 specifying ascending order. You can also provide an event handler for the Command event to programmatically control the action performed when the Command button is clicked.

Caution noteCaution:

This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input. For more information, see Validation Server Control Syntax.

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 all pass the validation rules specified by the validation control. To prevent page validation from occurring, set the CausesValidation property to false.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
How to: Add Button Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Add Button Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Add Button Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to User Clicks in BulletedList Web Server ControlsBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to User Clicks in BulletedList Web Server ControlsBuilding ASP .NET Web Applications in Visual Studio
How to: Respond to User Clicks in BulletedList Web Server Controls (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications in Visual Studio
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding Applications with Visual Web Developer
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio

The following example demonstrates how to create a LinkButton control that displays text in a Label control when the link is clicked.

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>LinkButton Example</title>
<script language="VB" runat="server">

      Sub LinkButton_Click(sender As Object, e As EventArgs) 
         Label1.Text = "You clicked the link button"
      End Sub

   </script>

</head>
<body>

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

      <h3>LinkButton Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Click Me" 
           Font-Names="Verdana" 
           Font-Size="14pt" 
           OnClick="LinkButton_Click" 
           runat="server"/>

      <br />

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

   </form>

</body>
</html>


C#
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>LinkButton Example</title>
<script language="C#" runat="server">

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

   </script>

</head>
<body>

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

      <h3>LinkButton Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Click Me" 
           Font-Names="Verdana" 
           Font-Size="14pt" 
           OnClick="LinkButton_Click" 
           runat="server"/>

      <br />

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

   </form>

</body>
</html>


JScript
<%@ Page Language="JScript" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>LinkButton Example</title>
<script language="JSCRIPT" runat="server">

      function LinkButton_Click(sender : Object, e : EventArgs){
         Label1.Text = "You clicked the link button"
      }

   </script>

</head>
<body>

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

      <h3>LinkButton Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Click Me" 
           Font-Names="Verdana" 
           Font-Size="14pt" 
           OnClick="LinkButton_Click" 
           runat="server"/>

      <br />

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

   </form>

</body>
</html>


System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.WebControl
      System.Web.UI.WebControls..::.LinkButton
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker