2

The question might sound dumb... but I have a code that is applying a css on a text box. now I want it to be set as default again on another condition.

Or to be precise I want to sent my textbox to its default style.

Searching on the internet and stackoverflow I have fount these answers -

Default textbox border-style and width

Any help?

EDIT :

    if (condition)
        {
            txtLastName.CssClass="ControlBackground_Yellow"; 
        }
    else
        {               
            txtLastName.CssClass="ControlBackground_White"; 
        }

css is --

ControlBackground_Yellow    
{
    background-color:#FFFF00;
}

ControlBackground_White     
{
    background-color:#FFFFFF;
}

PS:sorry not allowed to use jQuery

6
  • Can you elaborate, please? What's the code that's applying the CSS? You can probably do this just by removing the relevant class. Commented Jan 11, 2013 at 1:54
  • look here if I understand you correctly you are wanting to set the style this can be done in code as well look here WebControl.CssClass Property Commented Jan 11, 2013 at 1:56
  • adited the question to elaborate. Commented Jan 11, 2013 at 1:59
  • Why are you trying to do this server side? Surely, surely, surely, the logic controlling your css belongs in your javascript on the frontend? Commented Jan 11, 2013 at 1:59
  • no the code written is on my class file. Commented Jan 11, 2013 at 2:00

4 Answers 4

3

You can use jQuery to remove css class from your control based on certain condition:

 var $arrow = jQuery('<div class="arrow"></div>');

 $arrow.removeClass();

You can again add class:

 $arrow.addClass('className');
Sign up to request clarification or add additional context in comments.

2 Comments

sorry not allowed to use jQuery
Your answer is also correct as I have seen in various websites but the problem is that I just can't use JQuery.
0

Depending on your implementation you can either:

Use jQuery to remove/addClasses on your textbox:

  $('input[type=text].yourClass#yourId)).removeClass('class_to_remove');
  $('input[type=text].yourClass#yourId)).removeClass('class_to_add');

Or use jQuery to directly set css values:

  $('input[type=text].yourClass#yourId)).css('display', 'block');
  $('input[type=text].yourClass#yourId)).css('border-color', 'red');

Comments

0

I just removed this line

   background-color:#FFFFFF;

from my css.

    ControlBackground_Yellow    
{
    background-color:#FFFF00;
}

ControlBackground_White     
{
    background-color:#FFFFFF;
}

thanks guys for ur help.

Comments

0

Can try this line from code behind as well:

textBox.Attributes.Remove("class");

The word "class" points to the current class applied to the textBox, does not need to replace this text. Hope it helps.

Comments

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.