?
Solved

Assign CSS class to a checkbox control

Posted on 2005-05-04
8
Medium Priority
?
593 Views
Last Modified: 2008-02-01
Hi I have a checkbox and I was it to have a css class named "checkbox" so it would look like:

<input type="checkbox" class="checkbox" id="Checkbox1" runat="server"....>

I used the cssclass property, tried using the .Attributes.Add and .Attributes.AddAtributtes methods. All 3 did the same thing:
they put a span tag around the checbox and put the class name in the span tag......

How can i get the class name in the checkbox (input tag) instead of the span tag.

(i program using vb.net )

thanks!
0
Comment
Question by:Kai77
8 Comments
 
LVL 6

Accepted Solution

by:
dharmesh_amity earned 375 total points
ID: 13926176
That's a bit of a problem.

There are two ways. First not that simple to do. You will have to inherit the checkbox class and override the render method and use your control instead.

OR

You can use a trick here.

You have css class

.checkbox{
...
..
}

right

so instead just keep it empty
.checkbox{
}

and then declare another rule for input element that will occur in the checkbox class

.checkbox input{

...
..
}

copy your the style here.

Hope this works

Thanks
0
 
LVL 33

Expert Comment

by:raterus
ID: 13926187
Heh, that's a good question, I couldn't figure that out either.  You may just want to use another strategy, and just use the HtmlInputCheckbox, and forget about the CheckBox control.  At least that you can customize exactly how you want.

--Michael
0
 

Author Comment

by:Kai77
ID: 13926201
Why didn't Microsoft made this easier?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:dharmesh_amity
ID: 13926223
Because that's Microsoft. Things work very easily when you have common scenarios, but when you want to do something that you want, then good luck with microsoft technology. Bang your head.
0
 
LVL 33

Expert Comment

by:raterus
ID: 13926259
Make a mental note of the red-flags and just know to be warned next time you run into that situation.  I've got plenty on my list..  For example I don't think I'd ever use the checkboxlist or radiobuttonlist controls again, they are awful, you can't customize an individual items at all, the same pretty much goes for the dropdownlist/listbox, but usually you don't need as fine control over the items.
0
 
LVL 6

Expert Comment

by:dharmesh_amity
ID: 13926280
Actually try the second option which I gave. I am pretty sure that will work.
0
 
LVL 33

Expert Comment

by:raterus
ID: 13926303
yeah, I agree dharmesh's second option is the most feasible and still allows you to use the CheckBox control.
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 13926321
The ASPX CheckBox is not just the box, it is also the associated label, so if you didn't use the SPAN, setting the cssClass property would not affect the Text associated with the label, which might be bad.

Another option is to use a javascript entry at the end of your page with

<Script type=text/javascript>
document.getElementById("CheckBox1").className = "classname";
</script>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question