tags:

views:

82

answers:

2

I am having a problem in that a style is not being applied when I used an "ID" selector (#btnOK). However, if I use a class selector (.btnOK, by changing the "#btnOK" to a ".btnOK" in the CSS file), the style is applied.

Any idea why? The style IS also applied in design mode, but not at run time. It's findingf the css file, else, the class wouldn't be applied. Case sensitivity match on the ID.

In the web page:

<link href="CSS/CvCost.css" rel="stylesheet" type="text/css" />

<asp:Button ID="btnOK" CssClass="btnOK" runat="server" Text="OK" ValidationGroup="Add"/>

In CSS/CvCost.css:

#btnOK{
    margin-right:5px;
    margin-top:5px;
    float:right;
    width:75px;
    height: 25px;
}
+1  A: 

If I recall correctly the ID that will show up when the code is ran/debugged wouldn't be the same as #btnOK. VS will give it another ID to go by when the code is ran.

This is done by ASP.Net, not Visual Studio.
SLaks
+2  A: 

ASP.Net will automatically generate unique IDs based on the element's container.

You need to use ASP.Net's actual ClientID.
Since you can't do that in an external CSS file, you should just use a class selector.

If you're using ASP.Net 4, you can also set the new ClientIDMode property to Static.

SLaks
Thank you and to all.
Velika
That's good to know about the ClientIDMode property, thx. I'm looking fwd to the release in March.
Velika