Something to watch out for

Discussion in 'ASP .Net' started by tdavisjr, Jan 3, 2006.

  1. tdavisjr

    tdavisjr Guest

    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?
    tdavisjr, Jan 3, 2006
    #1
    1. Advertising

  2. tdavisjr

    clintonG Guest

    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/


    "tdavisjr" <> wrote in message
    news:...
    >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?
    >
    clintonG, Jan 4, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Words to Watch Out For

    Kevin Spencer, May 20, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    344
  2. Guest
    Replies:
    4
    Views:
    465
    Guest
    Oct 13, 2004
  3. Replies:
    0
    Views:
    241
  4. Erik Veenstra
    Replies:
    0
    Views:
    74
    Erik Veenstra
    Jan 27, 2006
  5. Replies:
    40
    Views:
    378
    John Lam (CLR)
    Aug 6, 2007
Loading...

Share This Page