asp.net - How to change a Panel border color programmatically

Panel border color
Panel is an asp.net web server control which acts as a container control for other controls. panel server control's have a built in property to dynamically assign its border color at run time.

panel control's BorderColor property get or set the border control of panel server control. the BorderColor property value type is System.Drawing.Color. this 'Color' represents the border color of panel server control. we need to import the System.Drawing namespace to set the border color of panel control's propgrammatically. we can simply put any valid color name for BorderColor property value such as Red, Green, Blue, Yellow etc.

the following asp.net c# example code demonstrate us how can we set or change panel web server control's border color programmatically at run time in an asp.net application.
PanelBorderColor.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Panel1.BorderColor = Color.IndianRed;

    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Panel1.BorderColor = Color.Tomato;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change Panel border color programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Panel Example: BorderColor</h2>
        <asp:Panel 
             ID="Panel1"
             runat="server"
             Height="150"
             Width="350"
             HorizontalAlign="Center"
             ForeColor="SandyBrown"
             BackColor="PeachPuff"
             BorderWidth="2"
             >
             <br /><br />
             <h2>Panel Border Color</h2>
        </asp:Panel>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="SaddleBrown"
             Text="Panel BorderColor IndianRed"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="SaddleBrown"
             Text="Panel BorderColor Tomato"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples