- How to change LinkButton style programmatically

Set or change LinkButton style programmatically
LinkButton is an ASP.NET web server control which appear as a Hyperlink control but has the same functionality of a button control. LinkButton has many built in properties to change its look and feel programmatically at run time such as ForeColor, BackColor, BorderColor, BorderStyle, BorderWidth, Height, Width, Font etc.

LinkButton ForeColor property allow us to change its text color. BackColor property help to change its background color. BorderColor property get or set the border color of LinkButton control. We can control the LinkButton font style by using its Font property sub properties such as font size, font name, font italic, font bold, font underline etc. BorderStyle property allow to apply a border style of LinkButton control.

The following c# example code demonstrate us how can we set or change LinkButton style programmatically at run time in an ASP.NET application.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
        LinkButton1.ForeColor = System.Drawing.Color.Crimson;
        LinkButton1.BackColor = System.Drawing.Color.Honeydew;
        LinkButton1.BorderColor = System.Drawing.Color.DarkRed;
        LinkButton1.Font.Size = FontUnit.XLarge;
        LinkButton1.Font.Italic = true;
        LinkButton1.BorderWidth = 2;

<html xmlns="">
<head id="Head1" runat="server">
    <title>How to set, change LinkButton style programmatically</title>
    <form id="form1" runat="server">
        <h2 style="color:Navy">LinkButton Example: Style</h2>
             Text="LinkButton Style Test"
        <br /><br />
             Text="Change LinkButton Style"

Related examples