I was extensively using Masterpages today and I discovered a behavior
that had me stumped for about 1/2 hour.
If you create a aspx page that uses a Masterpage and you define a text
box server control and give it an ID of txtName. Now, let say you want
to style that textbox so with css you use the ID selector to give the
textbox a style like so:
#txtName
{
color: Yellow;
}
Now, you go to run that page and the text box isn't styled the way you
want, it looks normal. This is because that when the server control in
rendered on the client it is pre-fixed with a unique name like:
_ctl0:mainContent:txtName
_ctl0 => the first control
mainContent => this is the ID I gave the content placeholder in my
MasterPage
txtName => the ID of the textbox
Therefore, the ID that is rendered in the client is NOT the same ID
selector you defined in your css and your server control don't get
styled. This behavior happens to anything you define as
runat="server", which all server controls has this attribute.
So, lessons learned. Its seems like this is where Themes and Skins
come to the rescue. OR, instead of using the ID selector in your css
use the class dot (.class ) synthax.
Anyone else had this similar experience?