tags:

views:

44

answers:

2

I have a Master Page which has an associated css file. On one of the base pages I have a div to which I am trying to apply a style from this css file by id. However, the page when rendered has a different id for this element.

How can I specify the correct id name in the css file?

Is there a way to specify that I want the id of this element like there is in javascript using the <%= Element.ClientID %>?

+2  A: 

You should be using class="someClass" for this instead of by the id. If you MUST use an id, put a container around it you know will not change, and give it an id, then do this

#myContainer .someClass {
...
}
Zoidberg
Can you give an example of a container which would not be modified by the usage of a master pages?
mwright
<div id="myContainer">, span, h1, ... you get the picture. So for example, <div id="myContainer"> div generated by asp.net with CssClass="someClass" </div>
Steve
+3  A: 

As best practice you should use the CssClass property to handle the look and feel of page controls. And for the page UI use the ID property which are commonly not controls and have child elements.

Controls

<asp:Label id="lblTest" CssClass="label" runat="Server">Test</Label>

Parent Elements

<div id="someid">
      <asp:Label id="lblTest" CssClass="label" runat="Server">Test</Label>
</div>
JeremySpouken
This was helpful, thank you.
mwright
Thanks for the elaboration... its been a year and a half since I have done .NET so I was a bit rusty on that point.
Zoidberg