asp.net.ph

Skip Navigation Links

LinkButton Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


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

Declarative Syntax

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.

Remarks

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.

Syntax Example

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>
  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>
See Also

LinkButton Class   Button Web Server Controls



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note