asp.net - How to change a LinkButton background color programmatically

Set or change LinkButton BackColor (BackGround color)
LinkButton is an asp.net web server control which render a hyperlink-style button control on web browser. linkbutton server control have a built in property to change its background color programmatically at run time.

linkbutton BackColor property get or set the background color of linkbutton control. so by using this property we can set or change linkbutton background color dynamically at run time. this property value type is System.Drawing.Color. this 'Color' represents the background color of the linkbutton control. BackColor property default value is Empty which means no background color is set. we need to import System.Drawing namespace to assign linkbutton background color programmatically.

the following asp.net c# example code demonstrate us how can we assign or change linkbutton background color programmatically at run time in an asp.net application. in this example we assign LightPink or LightGoldenrodyellow color as linkbutton background color by two button click event.
LinkButtonBackColor.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        LinkButton1.BackColor = System.Drawing.Color.LightPink;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        LinkButton1.BackColor = System.Drawing.Color.LightGoldenrodYellow;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change LinkButton BackColor (BackGround color)</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">LinkButton Example: BackColor</h2>
        <asp:LinkButton 
             ID="LinkButton1" 
             runat="server"
             Text="LinkButton BackColor Test"
             Height="25"
             ForeColor="Crimson"
             >
        </asp:LinkButton>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="Crimson"
             Text="LinkButton LightPink"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="Crimson"
             Text="LinkButton LightGoldenrodYellow"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>








Related asp.net example