I have a method to get a random color:
private System.Drawing.Color GetRandColor()
{
Random r = new Random(DateTime.Now.Millisecond);
System.Drawing.Color[] colours =
{
System.Drawing.Color.Yellow,
System.Drawing.Color.LightGreen,
System.Drawing.Color.LightCyan,
System.Drawing.Color.LightSalmon,
System.Drawing.Color.LightSkyBlue
};
int i = r.Next(0, colours.Length - 1);
System.Drawing.Color c = colours[i];
return c;
}
So what I want to do, is to have this random color passed into my html when the page loads.
So it will be put in Page_Load somehow:
protected void Page_Load(object sender, EventArgs e)
{
// code to set button color
}
<asp:Button ID="Button1" runat="server" Text="Button" BackColor=GetRandColor()/>
You can change the background color of button in C# code itself. Please check the method.