Click event in LinkButton control
LinkButton is an ASP.NET web server control. The LinkButton server control renders a hyperlink-style button control on the web page. Though it looks like a hyperlink it has the same functionality as a Button control. By default, a LinkButton control is a submit Button. We also can use it as a command button.
When we use LinkButton control as a regular submit button, we can provide an event handler for its Click event. Submit button simply posts the web page back to the server. This Click event allows us to programmatically control the action performed the submit Button (LinkButton) is clicked.
The LinkButton Click event occurs when the LinkButton control is clicked. The click event is commonly used when no command name is associated with the LinkButton control.
The LinkButton OnClick method raises the Click event of the LinkButton control. The OnClick method required a parameter named e. this parameter type is System.EventArgs that contains the event data.
The following ASP.NET C# example code demonstrates to us how can we use LinkButton click event in an ASP.NET application.
When we use LinkButton control as a regular submit button, we can provide an event handler for its Click event. Submit button simply posts the web page back to the server. This Click event allows us to programmatically control the action performed the submit Button (LinkButton) is clicked.
The LinkButton Click event occurs when the LinkButton control is clicked. The click event is commonly used when no command name is associated with the LinkButton control.
The LinkButton OnClick method raises the Click event of the LinkButton control. The OnClick method required a parameter named e. this parameter type is System.EventArgs that contains the event data.
The following ASP.NET C# example code demonstrates to us how can we use LinkButton click event in an ASP.NET application.
LinkButtonOnClick.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void LinkButton1_Click(object sender, System.EventArgs e)
{
Label1.Text = "Your Address:<br />" + TextBox1.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use OnClick event in LinkButton control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">LinkButton Example: OnClick Event</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
ForeColor="HotPink"
Font-Italic="true"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Label
ID="Label2"
runat="server"
Font-Bold="true"
ForeColor="DodgerBlue"
Text="Address"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
BackColor="LightGoldenrodYellow"
ForeColor="DodgerBlue"
TextMode="MultiLine"
>
</asp:TextBox>
<br /><br />
<asp:LinkButton
ID="LinkButton1"
runat="server"
Text="Submit Address"
OnClick="LinkButton1_Click"
ForeColor="Crimson"
Font-Size="Large"
BorderWidth="2"
>
</asp:LinkButton>
</div>
</form>
</body>
</html>