Overriding the ClientID

Discussion in 'ASP .Net' started by Iain, Mar 2, 2006.

  1. Iain

    Iain Guest

    I'm writing a server control which is a navigation bar.

    My prototype uses id based styles to control the layout and dynamics.

    Is there any way I can override asp.net's processing of the ID so that the
    ID will be the one I want regardless of the containing page and so on?

    Iain
    --
    Iain Downs (DirectShow MVP)
    Commercial Software Therapist
    www.idcl.co.uk
     
    Iain, Mar 2, 2006
    #1
    1. Advertising

  2. Iain,
    I'm sure there is a way to change the id howabout me.id = "Iain1" but it
    probably will cause problems with your control working in some environments.
    A more structured design approach is to use a custom property in your
    control. You get the bonus of having designer support. Make a quick change
    to your prototype to include a property for the styles. Store the styles in
    an enumeration. Use your new StyleType property to control the navigation
    rendering.

    imports system.componentmodel

    <Category("Style")> _
    Public Property StyleType() As st
    Get
    Return _StyleType
    End Get
    Set(ByVal value As st)
    _StyleType = value
    End Set
    End Property
    Public Enum st As Integer
    Space = 1
    Earth = 2
    Valley = 0
    End Enum
    Private _StypeType As st = st.Space 'space is default in this example
    ....
    if me.StyleType = st.Space then
    ' make background black have fun Iain!
    ....
    endif

    Good Luck
    DWS


    "Iain" wrote:

    > I'm writing a server control which is a navigation bar.
    >
    > My prototype uses id based styles to control the layout and dynamics.
    >
    > Is there any way I can override asp.net's processing of the ID so that the
    > ID will be the one I want regardless of the containing page and so on?
    >
    > Iain
    > --
    > Iain Downs (DirectShow MVP)
    > Commercial Software Therapist
    > www.idcl.co.uk
    >
     
    =?Utf-8?B?RFdT?=, Mar 3, 2006
    #2
    1. Advertising

  3. Iain

    Iain Guest

    On Fri, 3 Mar 2006 07:25:27 -0800, DWS wrote:

    Thank's for your input DWS.

    Unfortunately, that won't quite do what I want.

    Me.ID = "Iain" will end up in the html as something link

    ID="Ctl100_Hider_Clt102_SomeContainer_Ctl100_Iain"

    since the actual ID in the html depends on whereabouts in the control
    hierarchy control actually is.

    CLientID holds this value but it's read only.

    One sort of work around is to use a named class rather than an ID based
    class in the style sheet (that is add class="MyClass") and set this in the
    control. This would work, but there's some risk of accidental collisions
    (ID's must be unique but classes need not be).

    In the end (for now, anyway), I've bypassed all the cleverness and coded up
    the important bits as raw html in a literal control...

    Iain
    > Iain,
    > I'm sure there is a way to change the id howabout me.id = "Iain1" but it
    > probably will cause problems with your control working in some environments.
    > A more structured design approach is to use a custom property in your
    > control. You get the bonus of having designer support. Make a quick change
    > to your prototype to include a property for the styles. Store the styles in
    > an enumeration. Use your new StyleType property to control the navigation
    > rendering.
    >
    > imports system.componentmodel
    >
    > <Category("Style")> _
    > Public Property StyleType() As st
    > Get
    > Return _StyleType
    > End Get
    > Set(ByVal value As st)
    > _StyleType = value
    > End Set
    > End Property
    > Public Enum st As Integer
    > Space = 1
    > Earth = 2
    > Valley = 0
    > End Enum
    > Private _StypeType As st = st.Space 'space is default in this example
    > ...
    > if me.StyleType = st.Space then
    > ' make background black have fun Iain!
    > ...
    > endif
    >
    > Good Luck
    > DWS
    >
    >
    > "Iain" wrote:
    >
    >> I'm writing a server control which is a navigation bar.
    >>
    >> My prototype uses id based styles to control the layout and dynamics.
    >>
    >> Is there any way I can override asp.net's processing of the ID so that the
    >> ID will be the one I want regardless of the containing page and so on?
    >>
    >> Iain
    >> --
    >> Iain Downs (DirectShow MVP)
    >> Commercial Software Therapist
    >> www.idcl.co.uk
    >>



    --
    Iain Downs (DirectShow MVP)
    Commercial Software Therapist
    www.idcl.co.uk
     
    Iain, Mar 3, 2006
    #3
  4. Iain,
    Sorry I really wanted to help.

    Good Luck
    DWS

    Spaming group with navigation controls The DWS custom navigation control is
    chocked full of custom properties. Just a navigation control on a panel but
    it has tooltips, images, and uses a custom sitemap provider. The, alignment,
    style properties, fonts and background color can be changed by users at
    runtime.

    Check it out.
    http://www.dws400.com/default.aspx?p=nbaeast


    "Iain" wrote:

    > On Fri, 3 Mar 2006 07:25:27 -0800, DWS wrote:
    >
    > Thank's for your input DWS.
    >
    > Unfortunately, that won't quite do what I want.
    >
    > Me.ID = "Iain" will end up in the html as something link
    >
    > ID="Ctl100_Hider_Clt102_SomeContainer_Ctl100_Iain"
    >
    > since the actual ID in the html depends on whereabouts in the control
    > hierarchy control actually is.
    >
    > CLientID holds this value but it's read only.
    >
    > One sort of work around is to use a named class rather than an ID based
    > class in the style sheet (that is add class="MyClass") and set this in the
    > control. This would work, but there's some risk of accidental collisions
    > (ID's must be unique but classes need not be).
    >
    > In the end (for now, anyway), I've bypassed all the cleverness and coded up
    > the important bits as raw html in a literal control...
    >
    > Iain
    > > Iain,
    > > I'm sure there is a way to change the id howabout me.id = "Iain1" but it
    > > probably will cause problems with your control working in some environments.
    > > A more structured design approach is to use a custom property in your
    > > control. You get the bonus of having designer support. Make a quick change
    > > to your prototype to include a property for the styles. Store the styles in
    > > an enumeration. Use your new StyleType property to control the navigation
    > > rendering.
    > >
    > > imports system.componentmodel
    > >
    > > <Category("Style")> _
    > > Public Property StyleType() As st
    > > Get
    > > Return _StyleType
    > > End Get
    > > Set(ByVal value As st)
    > > _StyleType = value
    > > End Set
    > > End Property
    > > Public Enum st As Integer
    > > Space = 1
    > > Earth = 2
    > > Valley = 0
    > > End Enum
    > > Private _StypeType As st = st.Space 'space is default in this example
    > > ...
    > > if me.StyleType = st.Space then
    > > ' make background black have fun Iain!
    > > ...
    > > endif
    > >
    > > Good Luck
    > > DWS
    > >
    > >
    > > "Iain" wrote:
    > >
    > >> I'm writing a server control which is a navigation bar.
    > >>
    > >> My prototype uses id based styles to control the layout and dynamics.
    > >>
    > >> Is there any way I can override asp.net's processing of the ID so that the
    > >> ID will be the one I want regardless of the containing page and so on?
    > >>
    > >> Iain
    > >> --
    > >> Iain Downs (DirectShow MVP)
    > >> Commercial Software Therapist
    > >> www.idcl.co.uk
    > >>

    >
    >
    > --
    > Iain Downs (DirectShow MVP)
    > Commercial Software Therapist
    > www.idcl.co.uk
    >
     
    =?Utf-8?B?RFdT?=, Mar 3, 2006
    #4
    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. John

    Odd clientID behaviour

    John, Aug 20, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    379
  2. Maras
    Replies:
    1
    Views:
    3,131
    Cowboy \(Gregory A. Beamer\)
    Oct 15, 2003
  3. oafyuf

    Databinding by ClientID

    oafyuf, Oct 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    700
    Mike Moore [MSFT]
    Oct 24, 2003
  4. jm
    Replies:
    2
    Views:
    5,969
    Marshal Antony
    Feb 12, 2004
  5. Henri
    Replies:
    2
    Views:
    12,112
    Henri
    May 18, 2004
Loading...

Share This Page