Something to watch out for

T

tdavisjr

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?
 
C

clintonG

Yea me. Micrsoft breaks everything and calls it progress ;-)
I never considered much value to the singular use of the id selector as
opposed to the class selector anyway. Its Microsoft's failure to support
other selectors that are much more useful that remains problematic for the
next five years or so.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top