ASP.NET LinkButton Control.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
The ASP.NET LinkButton is used as a hyperlink type button. The control is rendered as a HTML anchor (a) element.
Working example.
Click this to change color.
Creating the LinkButton control.
From the above example.
<asp:LinkButton ID="LinkButton1" runat="server" ForeColor="Blue" OnClick="LinkButton1_Click">Click this to change color.</asp:LinkButton>
The above example will be rendered as HTML with the result below (source).
<a id="ctl00_ContentPlaceHolder1_LinkButton1" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')" style="color:Blue;">Click this to change color.</a>
Responding to the click event.
<script runat="server">
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (this.LinkButton1.ForeColor == System.Drawing.Color.Blue)
{
this.LinkButton1.ForeColor = System.Drawing.Color.Red;
return;
}
if (this.LinkButton1.ForeColor == System.Drawing.Color.Red)
{
this.LinkButton1.ForeColor = System.Drawing.Color.Blue;
return;
}
}
</script>
|