James Wilson
James Wilson

Reputation: 5160

ASP.net server control checkbox misunderstanding

I am trying to use the server control for an asp checkbox:

<asp:CheckBox ID="generalInformation"
    ClientIDMode="Static"
    class="SetupChecklist"
    name="generalInformation"
    CssClass="SetupChecklist"
    runat="server" />

However it does not seem to be retaining the class, which I need it to do. Am I missing something?

Here is how it renders on the web page:

<input type="checkbox"
    name="ctl00$ContentPlaceHolder1$generalInformation"
    id="generalInformation">

Upvotes: 1

Views: 190

Answers (4)

Pankaj
Pankaj

Reputation: 10115

It will render the HTML like below.

<span class="SetupChecklist" class="SetupChecklist" name="generalInformation">
     <input id="generalInformation" type="checkbox" name="generalInformation" />
</span>

Assuming that you are trying to design the input tag.

Now your style sheet can be like below for the <input> tag

<style type="text/css">
    .SetupChecklist input
    {
        border:0px;
    }
</style>

Originally, the span tag was occupying the class information.

Upvotes: 1

Royi Namir
Royi Namir

Reputation: 148744

ah.......

this is the problem:

runat="server" checkbox is render to span + input...

the span gets the class not the input....

 <span class="SetupChecklist" class="SetupChecklist" name="generalInformation">
<input id="generalInformation" type="checkbox" name="generalInformation" /></span>

Upvotes: 1

derek
derek

Reputation: 4886

remove the class attribute and just use the CssClass

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460370

You might want to use the CssClass property instead:

<asp:CheckBox ID="generalInformation"
    ClientIDMode="Static"
    name="generalInformation"
    CssClass="SetupChecklist"
    runat="server" />

Edit: I've only just seen that you've already tried it. Ok, CssClass actually applies the class to a span that wraps the check box, so try this instead:

generalInformation.InputAttributes("class", "SetupChecklist"); 

Upvotes: 1

Related Questions