0

I have CSS classfile. So when I click on button the buttontext should be in green.

.buttongreen
{
    color:green;    
}
Opal
  • 81,889
  • 28
  • 189
  • 210
Kaushal
  • 11
  • 1
  • 1
  • 5

5 Answers5

2

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;
}
Amna
  • 603
  • 7
  • 30
  • 1
    i think we can do change by this way you showed. but i am trying to do with using CssClass file . – Kaushal May 20 '15 at 15:52
1

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");
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
1

You can do it in two ways:

  1. Using javascript

    <script type="text/javascript">
    
    function changeColor()
    

    {

    document.getElementById("buttonName").className = "MyClass";
    

    }

    <script>
    

call this function OnClientClick

  1. In code behind

    btnName.Attributes.Add("class", "buttongreen");

killer
  • 592
  • 1
  • 9
  • 31
1

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.

0

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";
}