Update:
The inline style on your button is preventing the background color from showing up.
Here's why:
Consider the following ASPX code:
<!-- language: lang-html -->
<pre><code><asp:Button runat="server" ID="Button1" Text="Click Me!"
<b>style="background-color: yellow;"</b>/>
</code></pre>
This will render the following HTML:
<!-- language: lang-html -->
<pre><code><input type="submit" id="MainContent_Button1" value="Click Me!"
<b>style="background-color: yellow;"</b>>
</code></pre>
When we add a BackColor
in the code behind, it prepends an inline style into the element's style attribute. Which produces this HTML:
<!-- language: lang-html -->
<pre><code><input type="submit" id="MainContent_Button1" value="Click Me!"
<b>style="background-color:Red;background-color: yellow;"></b>
</code></pre>
So it inserts the red color, but then the original color immediately overrides it.
To solve this, in your ASPX, use the BackColor
property instead of using the background-color
inline style tag. Like this:
<!-- language: lang-html -->
<pre><code><asp:Button ID="Button1" runat="server" Text="Submit"
<b>BackColor="#CC6600"</b> <strike>style="background-color:#CC6600;"</strike>/>
</code></pre>
ASP.NET will know how to properly override this when new colors are applied.
Original:
If you had to do this in JavaScript, You can use RegisterStartupScript
to send dynamic javascript code to the browser, but I suspect something else is at issue.
<!-- language: lang-cs -->
var script = "document.getElementById('" + Button1.ClientID + "').style.backgroundColor = 'red';";
ScriptManager.RegisterStartupScript(this, typeof(Page), "changecolor", script, true);