0

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

.buttongreen
{
    color:green;    
}
4
  • You want this in code behind ? Commented May 20, 2015 at 4:03
  • yes ,using CssClass file , marrying with Asp.net call on click event of button Commented May 20, 2015 at 16:07
  • Have u tried my answer ? Commented May 20, 2015 at 16:26
  • whre is your answer, anyways its done by the way thank you Commented May 20, 2015 at 16:41

5 Answers 5

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

i think we can do change by this way you showed. but i am trying to do with using CssClass file .
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");

1 Comment

Please see the answer here.
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");

1 Comment

i am trying to do with Using CssClass file .. if u can help me pls
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.

Comments

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

3 Comments

not hover change color Button Click Event Color Change.
it works thank u . what to do if i want to change 2 button text , using only present CssClass file, i mean if i change color to red in css file , it applies on all the button text.
as above have used button.cssClass, you just specify button names whose color you want to change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.