Reputation: 11
I have CSS classfile. So when I click on button the buttontext should be in green.
.buttongreen
{
color:green;
}
Upvotes: 0
Views: 16223
Reputation: 611
It can be done without changing any cssClass. You can change your button text color like this
void OnClick1(object sender, RoutedEventArgs e)
{
btn.Forecolor = System.Drawing.Color.Green;
}
Or you can change your button background color like this:
void OnClick1(object sender, RoutedEventArgs e)
{
btn.Backgroundcolor = System.Drawing.Color.Green;
}
Upvotes: 2
Reputation: 125
Change the foreground color of your button text from OnClick event.
button.Forecolor = System.Drawing.Color.Green;
I hope this will work for you without CSS.
Upvotes: 1
Reputation: 602
You can do it in two ways:
Using javascript
<script type="text/javascript">
function changeColor()
{
document.getElementById("buttonName").className = "MyClass";
}
<script>
call this function OnClientClick
In code behind
btnName.Attributes.Add("class", "buttongreen");
Upvotes: 1
Reputation: 26
I have updated my answer using cssClass OF button. Not sure but this may help you ..
protected void button_Click(object sender, EventArgs e)
{
button.CssClass = "buttongreen";
}
Upvotes: 0
Reputation: 14624
If you only want to change color of button in code behind than do this
btnName.Style.Add(HtmlTextWriterStyle.Color, "green");
Here btnName
is ID
of button.
And if you want to add a class than do this
btnName.Attributes.Add("class", "buttongreen");
Upvotes: 1