Prevent controls from inheirting ID of parent

Discussion in 'ASP .Net Web Controls' started by Alex, Sep 29, 2004.

  1. Alex

    Alex Guest

    I am building a grid which I am adding my own templated columns to. One of
    the columns has a checkbox and I am assiging the checkbox an ID based on the
    row of the griid. When the grid gets built, the checkbox ID is changed so
    that it is a combination of the parent control IDs and its id. Is there any
    way to prevent this behaviour?

    Thanks,

    Alex Gadea
     
    Alex, Sep 29, 2004
    #1
    1. Advertising

  2. Alex

    Teemu Keiski Guest

    Hi,

    not really unless you play with only client-side controls (e.g have
    client.side HTML which doesn't use server controls).

    Certainly you could get over it by assigning the ID (per row, whuch you get
    from db) to DataGrid's DataKeyField and get it from there when you get
    reference to any particular CheckBox in the grid (the current DataGridItem
    is Parent's Parent to the CheckBox in control hierarchy amd with
    DataGridItem you get the info on which row you are on the grid).

    Idea is exactly opposite to your custom naming that you don't acuyally need
    to name them yourself, you can use other means. One other way would be using
    just HTML checkboxes (<input type="checkbox" runat="server" />) for which
    you could according to the HTML model assign also value to the Value
    attribute/property. That's another place where you could place the ID
    special to the row/checkbox

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "Alex" <> wrote in message
    news:...
    > I am building a grid which I am adding my own templated columns to. One

    of
    > the columns has a checkbox and I am assiging the checkbox an ID based on

    the
    > row of the griid. When the grid gets built, the checkbox ID is changed so
    > that it is a combination of the parent control IDs and its id. Is there

    any
    > way to prevent this behaviour?
    >
    > Thanks,
    >
    > Alex Gadea
     
    Teemu Keiski, Sep 29, 2004
    #2
    1. Advertising

  3. Alex

    Alex Guest

    Actually, the big reason I wanted to override this is that we use Guids for
    our IDs and we wind up having a name and id property that approaches 100
    characters for each checkbox. And then you add 30 checkboxes to a page,
    you've suddenly got 1k worth of Ids for no particular reason.

    Alex

    "Teemu Keiski" wrote:

    > Hi,
    >
    > not really unless you play with only client-side controls (e.g have
    > client.side HTML which doesn't use server controls).
    >
    > Certainly you could get over it by assigning the ID (per row, whuch you get
    > from db) to DataGrid's DataKeyField and get it from there when you get
    > reference to any particular CheckBox in the grid (the current DataGridItem
    > is Parent's Parent to the CheckBox in control hierarchy amd with
    > DataGridItem you get the info on which row you are on the grid).
    >
    > Idea is exactly opposite to your custom naming that you don't acuyally need
    > to name them yourself, you can use other means. One other way would be using
    > just HTML checkboxes (<input type="checkbox" runat="server" />) for which
    > you could according to the HTML model assign also value to the Value
    > attribute/property. That's another place where you could place the ID
    > special to the row/checkbox
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > http://blogs.aspadvice.com/joteke
    >
    >
    > "Alex" <> wrote in message
    > news:...
    > > I am building a grid which I am adding my own templated columns to. One

    > of
    > > the columns has a checkbox and I am assiging the checkbox an ID based on

    > the
    > > row of the griid. When the grid gets built, the checkbox ID is changed so
    > > that it is a combination of the parent control IDs and its id. Is there

    > any
    > > way to prevent this behaviour?
    > >
    > > Thanks,
    > >
    > > Alex Gadea

    >
    >
    >
     
    Alex, Sep 29, 2004
    #3
  4. If you don't need GUIDs on the client side, I suggest you to take a
    different approach. On the server side you had to rebind the data to get the
    checkboxes, so you already have access to GUIDs. But if you need GUIDs, you
    could add them to some custom checkbox attribute:

    checkbox1.Attributes.Add("rowGUID", yourguid.ToString());

    Using this technique, attribute would be ignored by the client HTML parser
    and you could easily access guid (without regular expression changes to
    string) with Javascript or on the server.

    This way you could read the guids on the client and the server side.
    Checkbox IDs would stay as they are. Framework does the naming this way to
    prevent different controls to share the same ID, which would result in an
    error.

    --
    RobertK
    { Clever? No just smart. }


    "Alex" <> wrote in message
    news:...
    > Actually, the big reason I wanted to override this is that we use Guids

    for
    > our IDs and we wind up having a name and id property that approaches 100
    > characters for each checkbox. And then you add 30 checkboxes to a page,
    > you've suddenly got 1k worth of Ids for no particular reason.
    >
    > Alex
    >
    > "Teemu Keiski" wrote:
    >
    > > Hi,
    > >
    > > not really unless you play with only client-side controls (e.g have
    > > client.side HTML which doesn't use server controls).
    > >
    > > Certainly you could get over it by assigning the ID (per row, whuch you

    get
    > > from db) to DataGrid's DataKeyField and get it from there when you get
    > > reference to any particular CheckBox in the grid (the current

    DataGridItem
    > > is Parent's Parent to the CheckBox in control hierarchy amd with
    > > DataGridItem you get the info on which row you are on the grid).
    > >
    > > Idea is exactly opposite to your custom naming that you don't acuyally

    need
    > > to name them yourself, you can use other means. One other way would be

    using
    > > just HTML checkboxes (<input type="checkbox" runat="server" />) for

    which
    > > you could according to the HTML model assign also value to the Value
    > > attribute/property. That's another place where you could place the ID
    > > special to the row/checkbox
    > >
    > > --
    > > Teemu Keiski
    > > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > > ASP.NET Forum Moderator, AspAlliance Columnist
    > > http://blogs.aspadvice.com/joteke
    > >
    > >
    > > "Alex" <> wrote in message
    > > news:...
    > > > I am building a grid which I am adding my own templated columns to.

    One
    > > of
    > > > the columns has a checkbox and I am assiging the checkbox an ID based

    on
    > > the
    > > > row of the griid. When the grid gets built, the checkbox ID is

    changed so
    > > > that it is a combination of the parent control IDs and its id. Is

    there
    > > any
    > > > way to prevent this behaviour?
    > > >
    > > > Thanks,
    > > >
    > > > Alex Gadea

    > >
    > >
    > >
     
    Robert Koritnik, Sep 30, 2004
    #4
  5. Alex

    Alex Guest

    Actually, I just wound up rebuilding the checkbox controls using literals and
    doing my own management of the postback. A little more coding, but it
    eliminated my main problem which was the huge Ids that were being passed
    around.

    Thanks for the suggestion.

    Alex

    "Robert Koritnik" wrote:

    > If you don't need GUIDs on the client side, I suggest you to take a
    > different approach. On the server side you had to rebind the data to get the
    > checkboxes, so you already have access to GUIDs. But if you need GUIDs, you
    > could add them to some custom checkbox attribute:
    >
    > checkbox1.Attributes.Add("rowGUID", yourguid.ToString());
    >
    > Using this technique, attribute would be ignored by the client HTML parser
    > and you could easily access guid (without regular expression changes to
    > string) with Javascript or on the server.
    >
    > This way you could read the guids on the client and the server side.
    > Checkbox IDs would stay as they are. Framework does the naming this way to
    > prevent different controls to share the same ID, which would result in an
    > error.
    >
    > --
    > RobertK
    > { Clever? No just smart. }
    >
    >
    > "Alex" <> wrote in message
    > news:...
    > > Actually, the big reason I wanted to override this is that we use Guids

    > for
    > > our IDs and we wind up having a name and id property that approaches 100
    > > characters for each checkbox. And then you add 30 checkboxes to a page,
    > > you've suddenly got 1k worth of Ids for no particular reason.
    > >
    > > Alex
    > >
    > > "Teemu Keiski" wrote:
    > >
    > > > Hi,
    > > >
    > > > not really unless you play with only client-side controls (e.g have
    > > > client.side HTML which doesn't use server controls).
    > > >
    > > > Certainly you could get over it by assigning the ID (per row, whuch you

    > get
    > > > from db) to DataGrid's DataKeyField and get it from there when you get
    > > > reference to any particular CheckBox in the grid (the current

    > DataGridItem
    > > > is Parent's Parent to the CheckBox in control hierarchy amd with
    > > > DataGridItem you get the info on which row you are on the grid).
    > > >
    > > > Idea is exactly opposite to your custom naming that you don't acuyally

    > need
    > > > to name them yourself, you can use other means. One other way would be

    > using
    > > > just HTML checkboxes (<input type="checkbox" runat="server" />) for

    > which
    > > > you could according to the HTML model assign also value to the Value
    > > > attribute/property. That's another place where you could place the ID
    > > > special to the row/checkbox
    > > >
    > > > --
    > > > Teemu Keiski
    > > > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > > > ASP.NET Forum Moderator, AspAlliance Columnist
    > > > http://blogs.aspadvice.com/joteke
    > > >
    > > >
    > > > "Alex" <> wrote in message
    > > > news:...
    > > > > I am building a grid which I am adding my own templated columns to.

    > One
    > > > of
    > > > > the columns has a checkbox and I am assiging the checkbox an ID based

    > on
    > > > the
    > > > > row of the griid. When the grid gets built, the checkbox ID is

    > changed so
    > > > > that it is a combination of the parent control IDs and its id. Is

    > there
    > > > any
    > > > > way to prevent this behaviour?
    > > > >
    > > > > Thanks,
    > > > >
    > > > > Alex Gadea
    > > >
    > > >
    > > >

    >
    >
    >
     
    Alex, Sep 30, 2004
    #5
    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. Pete C
    Replies:
    6
    Views:
    831
    Ron Natalie
    Oct 30, 2005
  2. jbo5112

    Re: Inheirting constructor?

    jbo5112, Nov 12, 2010, in forum: C++
    Replies:
    2
    Views:
    294
    jbo5112
    Jan 5, 2011
  3. Replies:
    0
    Views:
    339
  4. Num GG
    Replies:
    2
    Views:
    408
    Num GG
    Nov 17, 2008
  5. cron
    Replies:
    8
    Views:
    689
    Thomas 'PointedEars' Lahn
    Oct 13, 2011
Loading...

Share This Page