Control names within a repeater

Discussion in 'ASP .Net' started by Ryan Ternier, Jul 23, 2004.

  1. Ryan Ternier

    Ryan Ternier Guest

    Hello,

    I have a repeater control that does the following on the ItemDataBound
    event. It works perfectly, except that when it prints out, the names of the
    controls
    aren't what I'd expect.

    lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we want form
    the DB

    I use that to set the ID of the listBox, but when it comes to the screen it
    has a name of

    rptSecurity:ctrl00:lstYes14

    Or something similar to that.

    Is there a way to make that control just have lstYes14?


    If Not e.Item.DataItem Is Nothing Then
    Try
    Dim intTypeID = CInt(Request.QueryString.Get("TypeID"))
    Dim objItemType As ItemType
    objItemType = New ItemType(CInt(intTypeID))

    'Get the current item that's being bound from the DB
    Dim drvTemp As DataRowView = CType(e.Item.DataItem, DataRowView)
    'Get handles on the server side controls so we can edit them through
    code. l337 pwn4g3
    Dim lstYes As ListBox = CType(e.Item.FindControl("listYes"),
    ListBox)
    Dim lstNo As ListBox = CType(e.Item.FindControl("listNo"), ListBox)
    Dim lblButtons As Label = CType(e.Item.FindControl("LabelButtons"),
    Label)
    Dim lblName As Label = CType(e.Item.FindControl("LabelName"), Label)


    lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we
    want form the DB
    lstYes.SelectionMode = ListSelectionMode.Multiple
    lstNo.ID = "lstN" & drvTemp("UserID") 'Assuming ID is the part we
    want form the DB
    lstNo.SelectionMode = ListSelectionMode.Multiple
    lblName.Text = drvTemp("FullName")
    'Response.Write(drvTemp("FullName") & "<BR>")
    For i As Integer = 0 To objItemType.Layout.Count() - 1
    lstYes.Items.Add(objItemType.Layout.Item(i).Field.Caption())
    lstYes.Items(i).Value = objItemType.Layout.Item(i).Field.FieldID
    Next

    'Put raw HTML into the Label control to build the 4 button table to move
    items between the list boxes.
    'To switch the items between listboxes
    'onclick="SwitchList(document.getElementById('lstNotifyAvailable'),
    document.getElementById('lstNotifySelected'));AdNotify(document.getElementBy
    Id('lstNotifyAvailable'));
    With lblButtons
    Text = "<table>"
    .Text &= "<tr><td>"
    .Text &= "<input type=""button"" class=""BoxType42""
    value=""Allow All"" name=""btn" & drvTemp("UserID") & "AA""
    onclick=""SwitchList(document.getElementById('" & lstYes.ID.ToString & "'),
    document.getElementById ('" & lstNo.ID.ToString &
    "'));AddNotify(document.getElementById('" & lstYes.ID.ToString() & "'));"">"
    .Text &= "</td></tr>"
    .Text &= "<tr><td>"
    .Text &= "<input type=""button"" class=""BoxType42""
    value=""Allow"" name=""btn" & drvTemp("UserID") & "A""
    onclick=""Allow(document.Security." & lstYes.ID.ToString() &
    ",document.Security." & lstNo.ID.ToString() & ");"">"
    .Text &= "</td></tr>"
    .Text &= "<tr><td>"
    .Text &= "<input type=""button"" class=""BoxType42""
    value=""Disallow All"" name=""btn" & drvTemp("UserID") & "DA""
    onclick=""DisAll(document.Security." & lstYes.ID.ToString() &
    ",document.Security." &
    lstNo.ID.ToString() & ");"">"
    .Text &= "</td></tr>"
    .Text &= "<tr><td>"
    .Text &= "<input type=""button"" class=""BoxType42""
    value=""Disallow"" name=""btn" & drvTemp("UserID") & "D""
    onclick=""Disallow(document.Security." & lstYes.ID.ToString() &
    ",document.Security." &
    lstNo.ID.ToString() & ");"">"
    .Text &= "</td></tr>"
    .Text &= "</table>"
    End With

    Catch ex As Exception
    Debug.WriteLine(ex.ToString)
    Response.Write("<BR>_______________________<BR>" & ex.ToString &
    "<BR>")
    Response.Flush()
    End Try

    End If
     
    Ryan Ternier, Jul 23, 2004
    #1
    1. Advertising

  2. Ryan Ternier

    Teemu Keiski Guest

    Hi,

    no there isn't. ASP.NET gives controls the IDs based on their location in
    control hierarchy and if control is contained in a naming container, which
    RepeaterItem is, it is named in new scope (scope of the repeaterItem where
    it is contained) and named according to that. This way it is ensured that
    every control has unique ID on the Page.

    What's the issue with this? You can get reference to the control via the
    RepeaterItem (callint RepeaterItem's FindControl method) and there you could
    use plain ID (lstYes14). If you need the ID at client-side, you can get it
    with controls ClientID property which returns the unique ID as
    clientscript-friendly. Also you can locate the control from top-level
    control (outside the Repeater) by using Page.FindControl and assigning the
    complete unique ID string, though seems that you are not looking for that.

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



    "Ryan Ternier" <> wrote in message
    news:...
    > Hello,
    >
    > I have a repeater control that does the following on the ItemDataBound
    > event. It works perfectly, except that when it prints out, the names of

    the
    > controls
    > aren't what I'd expect.
    >
    > lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we want

    form
    > the DB
    >
    > I use that to set the ID of the listBox, but when it comes to the screen

    it
    > has a name of
    >
    > rptSecurity:ctrl00:lstYes14
    >
    > Or something similar to that.
    >
    > Is there a way to make that control just have lstYes14?
    >
    >
    > If Not e.Item.DataItem Is Nothing Then
    > Try
    > Dim intTypeID = CInt(Request.QueryString.Get("TypeID"))
    > Dim objItemType As ItemType
    > objItemType = New ItemType(CInt(intTypeID))
    >
    > 'Get the current item that's being bound from the DB
    > Dim drvTemp As DataRowView = CType(e.Item.DataItem, DataRowView)
    > 'Get handles on the server side controls so we can edit them

    through
    > code. l337 pwn4g3
    > Dim lstYes As ListBox = CType(e.Item.FindControl("listYes"),
    > ListBox)
    > Dim lstNo As ListBox = CType(e.Item.FindControl("listNo"),

    ListBox)
    > Dim lblButtons As Label =

    CType(e.Item.FindControl("LabelButtons"),
    > Label)
    > Dim lblName As Label = CType(e.Item.FindControl("LabelName"),

    Label)
    >
    >
    > lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we
    > want form the DB
    > lstYes.SelectionMode = ListSelectionMode.Multiple
    > lstNo.ID = "lstN" & drvTemp("UserID") 'Assuming ID is the part we
    > want form the DB
    > lstNo.SelectionMode = ListSelectionMode.Multiple
    > lblName.Text = drvTemp("FullName")
    > 'Response.Write(drvTemp("FullName") & "<BR>")
    > For i As Integer = 0 To objItemType.Layout.Count() - 1
    > lstYes.Items.Add(objItemType.Layout.Item(i).Field.Caption())
    > lstYes.Items(i).Value =

    objItemType.Layout.Item(i).Field.FieldID
    > Next
    >
    > 'Put raw HTML into the Label control to build the 4 button table to move
    > items between the list boxes.
    > 'To switch the items between listboxes
    > 'onclick="SwitchList(document.getElementById('lstNotifyAvailable'),
    >

    document.getElementById('lstNotifySelected'));AdNotify(document.getElementBy
    > Id('lstNotifyAvailable'));
    > With lblButtons
    > Text = "<table>"
    > .Text &= "<tr><td>"
    > .Text &= "<input type=""button"" class=""BoxType42""
    > value=""Allow All"" name=""btn" & drvTemp("UserID") & "AA""
    > onclick=""SwitchList(document.getElementById('" & lstYes.ID.ToString &

    "'),
    > document.getElementById ('" & lstNo.ID.ToString &
    > "'));AddNotify(document.getElementById('" & lstYes.ID.ToString() &

    "'));"">"
    > .Text &= "</td></tr>"
    > .Text &= "<tr><td>"
    > .Text &= "<input type=""button"" class=""BoxType42""
    > value=""Allow"" name=""btn" & drvTemp("UserID") & "A""
    > onclick=""Allow(document.Security." & lstYes.ID.ToString() &
    > ",document.Security." & lstNo.ID.ToString() & ");"">"
    > .Text &= "</td></tr>"
    > .Text &= "<tr><td>"
    > .Text &= "<input type=""button"" class=""BoxType42""
    > value=""Disallow All"" name=""btn" & drvTemp("UserID") & "DA""
    > onclick=""DisAll(document.Security." & lstYes.ID.ToString() &
    > ",document.Security." &
    > lstNo.ID.ToString() & ");"">"
    > .Text &= "</td></tr>"
    > .Text &= "<tr><td>"
    > .Text &= "<input type=""button"" class=""BoxType42""
    > value=""Disallow"" name=""btn" & drvTemp("UserID") & "D""
    > onclick=""Disallow(document.Security." & lstYes.ID.ToString() &
    > ",document.Security." &
    > lstNo.ID.ToString() & ");"">"
    > .Text &= "</td></tr>"
    > .Text &= "</table>"
    > End With
    >
    > Catch ex As Exception
    > Debug.WriteLine(ex.ToString)
    > Response.Write("<BR>_______________________<BR>" & ex.ToString &
    > "<BR>")
    > Response.Flush()
    > End Try
    >
    > End If
    >
    >
     
    Teemu Keiski, Jul 23, 2004
    #2
    1. Advertising

  3. Ryan Ternier

    Ryan Ternier Guest

    The issue i'm having is my repeater will be repeating multiple sets of 2
    list boxes.

    I'm using client side JS to move items from 1 listbox to the other, for each
    repeating.

    I didn't know you could grab the ClientID property... i'll have to look into
    that, and see if I can get that to work.

    Thanks!
    "Teemu Keiski" <> wrote in message
    news:...
    > Hi,
    >
    > no there isn't. ASP.NET gives controls the IDs based on their location in
    > control hierarchy and if control is contained in a naming container, which
    > RepeaterItem is, it is named in new scope (scope of the repeaterItem where
    > it is contained) and named according to that. This way it is ensured that
    > every control has unique ID on the Page.
    >
    > What's the issue with this? You can get reference to the control via the
    > RepeaterItem (callint RepeaterItem's FindControl method) and there you

    could
    > use plain ID (lstYes14). If you need the ID at client-side, you can get it
    > with controls ClientID property which returns the unique ID as
    > clientscript-friendly. Also you can locate the control from top-level
    > control (outside the Repeater) by using Page.FindControl and assigning the
    > complete unique ID string, though seems that you are not looking for that.
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > http://blogs.aspadvice.com/joteke
    >
    >
    >
    > "Ryan Ternier" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a repeater control that does the following on the ItemDataBound
    > > event. It works perfectly, except that when it prints out, the names of

    > the
    > > controls
    > > aren't what I'd expect.
    > >
    > > lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we want

    > form
    > > the DB
    > >
    > > I use that to set the ID of the listBox, but when it comes to the screen

    > it
    > > has a name of
    > >
    > > rptSecurity:ctrl00:lstYes14
    > >
    > > Or something similar to that.
    > >
    > > Is there a way to make that control just have lstYes14?
    > >
    > >
    > > If Not e.Item.DataItem Is Nothing Then
    > > Try
    > > Dim intTypeID = CInt(Request.QueryString.Get("TypeID"))
    > > Dim objItemType As ItemType
    > > objItemType = New ItemType(CInt(intTypeID))
    > >
    > > 'Get the current item that's being bound from the DB
    > > Dim drvTemp As DataRowView = CType(e.Item.DataItem, DataRowView)
    > > 'Get handles on the server side controls so we can edit them

    > through
    > > code. l337 pwn4g3
    > > Dim lstYes As ListBox = CType(e.Item.FindControl("listYes"),
    > > ListBox)
    > > Dim lstNo As ListBox = CType(e.Item.FindControl("listNo"),

    > ListBox)
    > > Dim lblButtons As Label =

    > CType(e.Item.FindControl("LabelButtons"),
    > > Label)
    > > Dim lblName As Label = CType(e.Item.FindControl("LabelName"),

    > Label)
    > >
    > >
    > > lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part

    we
    > > want form the DB
    > > lstYes.SelectionMode = ListSelectionMode.Multiple
    > > lstNo.ID = "lstN" & drvTemp("UserID") 'Assuming ID is the part

    we
    > > want form the DB
    > > lstNo.SelectionMode = ListSelectionMode.Multiple
    > > lblName.Text = drvTemp("FullName")
    > > 'Response.Write(drvTemp("FullName") & "<BR>")
    > > For i As Integer = 0 To objItemType.Layout.Count() - 1
    > > lstYes.Items.Add(objItemType.Layout.Item(i).Field.Caption())
    > > lstYes.Items(i).Value =

    > objItemType.Layout.Item(i).Field.FieldID
    > > Next
    > >
    > > 'Put raw HTML into the Label control to build the 4 button table to move
    > > items between the list boxes.
    > > 'To switch the items between listboxes
    > > 'onclick="SwitchList(document.getElementById('lstNotifyAvailable'),
    > >

    >

    document.getElementById('lstNotifySelected'));AdNotify(document.getElementBy
    > > Id('lstNotifyAvailable'));
    > > With lblButtons
    > > Text = "<table>"
    > > .Text &= "<tr><td>"
    > > .Text &= "<input type=""button"" class=""BoxType42""
    > > value=""Allow All"" name=""btn" & drvTemp("UserID") & "AA""
    > > onclick=""SwitchList(document.getElementById('" & lstYes.ID.ToString &

    > "'),
    > > document.getElementById ('" & lstNo.ID.ToString &
    > > "'));AddNotify(document.getElementById('" & lstYes.ID.ToString() &

    > "'));"">"
    > > .Text &= "</td></tr>"
    > > .Text &= "<tr><td>"
    > > .Text &= "<input type=""button"" class=""BoxType42""
    > > value=""Allow"" name=""btn" & drvTemp("UserID") & "A""
    > > onclick=""Allow(document.Security." & lstYes.ID.ToString() &
    > > ",document.Security." & lstNo.ID.ToString() & ");"">"
    > > .Text &= "</td></tr>"
    > > .Text &= "<tr><td>"
    > > .Text &= "<input type=""button"" class=""BoxType42""
    > > value=""Disallow All"" name=""btn" & drvTemp("UserID") & "DA""
    > > onclick=""DisAll(document.Security." & lstYes.ID.ToString() &
    > > ",document.Security." &
    > > lstNo.ID.ToString() & ");"">"
    > > .Text &= "</td></tr>"
    > > .Text &= "<tr><td>"
    > > .Text &= "<input type=""button"" class=""BoxType42""
    > > value=""Disallow"" name=""btn" & drvTemp("UserID") & "D""
    > > onclick=""Disallow(document.Security." & lstYes.ID.ToString() &
    > > ",document.Security." &
    > > lstNo.ID.ToString() & ");"">"
    > > .Text &= "</td></tr>"
    > > .Text &= "</table>"
    > > End With
    > >
    > > Catch ex As Exception
    > > Debug.WriteLine(ex.ToString)
    > > Response.Write("<BR>_______________________<BR>" & ex.ToString &
    > > "<BR>")
    > > Response.Flush()
    > > End Try
    > >
    > > End If
    > >
    > >

    >
    >
     
    Ryan Ternier, Jul 23, 2004
    #3
  4. Ryan Ternier

    Shan Plourde Guest

    I've had to do this a few times. Here's a code snippet:
    <a
    href="javascript:eek:penWin('<%= tbCompanyName.UniqueID.Replace(":",
    "_") %>', '<%= tbCompanyId.UniqueID.Replace(":", "_") %>')">Find</a>

    This code snippet calls a javascript function. Control.UniqueID gives
    you the full name of a control
    Shan Plourde

    Ryan Ternier wrote:

    >The issue i'm having is my repeater will be repeating multiple sets of 2
    >list boxes.
    >
    >I'm using client side JS to move items from 1 listbox to the other, for each
    >repeating.
    >
    >I didn't know you could grab the ClientID property... i'll have to look into
    >that, and see if I can get that to work.
    >
    >Thanks!
    >"Teemu Keiski" <> wrote in message
    >news:...
    >
    >
    >>Hi,
    >>
    >>no there isn't. ASP.NET gives controls the IDs based on their location in
    >>control hierarchy and if control is contained in a naming container, which
    >>RepeaterItem is, it is named in new scope (scope of the repeaterItem where
    >>it is contained) and named according to that. This way it is ensured that
    >>every control has unique ID on the Page.
    >>
    >>What's the issue with this? You can get reference to the control via the
    >>RepeaterItem (callint RepeaterItem's FindControl method) and there you
    >>
    >>

    >could
    >
    >
    >>use plain ID (lstYes14). If you need the ID at client-side, you can get it
    >>with controls ClientID property which returns the unique ID as
    >>clientscript-friendly. Also you can locate the control from top-level
    >>control (outside the Repeater) by using Page.FindControl and assigning the
    >>complete unique ID string, though seems that you are not looking for that.
    >>
    >>--
    >>Teemu Keiski
    >>MCP, Microsoft MVP (ASP.NET), AspInsiders member
    >>ASP.NET Forum Moderator, AspAlliance Columnist
    >>http://blogs.aspadvice.com/joteke
    >>
    >>
    >>
    >>"Ryan Ternier" <> wrote in message
    >>news:...
    >>
    >>
    >>>Hello,
    >>>
    >>>I have a repeater control that does the following on the ItemDataBound
    >>>event. It works perfectly, except that when it prints out, the names of
    >>>
    >>>

    >>the
    >>
    >>
    >>>controls
    >>>aren't what I'd expect.
    >>>
    >>>lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we want
    >>>
    >>>

    >>form
    >>
    >>
    >>>the DB
    >>>
    >>>I use that to set the ID of the listBox, but when it comes to the screen
    >>>
    >>>

    >>it
    >>
    >>
    >>>has a name of
    >>>
    >>>rptSecurity:ctrl00:lstYes14
    >>>
    >>>Or something similar to that.
    >>>
    >>>Is there a way to make that control just have lstYes14?
    >>>
    >>>
    >>>If Not e.Item.DataItem Is Nothing Then
    >>> Try
    >>> Dim intTypeID = CInt(Request.QueryString.Get("TypeID"))
    >>> Dim objItemType As ItemType
    >>> objItemType = New ItemType(CInt(intTypeID))
    >>>
    >>> 'Get the current item that's being bound from the DB
    >>> Dim drvTemp As DataRowView = CType(e.Item.DataItem, DataRowView)
    >>> 'Get handles on the server side controls so we can edit them
    >>>
    >>>

    >>through
    >>
    >>
    >>>code. l337 pwn4g3
    >>> Dim lstYes As ListBox = CType(e.Item.FindControl("listYes"),
    >>>ListBox)
    >>> Dim lstNo As ListBox = CType(e.Item.FindControl("listNo"),
    >>>
    >>>

    >>ListBox)
    >>
    >>
    >>> Dim lblButtons As Label =
    >>>
    >>>

    >>CType(e.Item.FindControl("LabelButtons"),
    >>
    >>
    >>>Label)
    >>> Dim lblName As Label = CType(e.Item.FindControl("LabelName"),
    >>>
    >>>

    >>Label)
    >>
    >>
    >>> lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part
    >>>
    >>>

    >we
    >
    >
    >>>want form the DB
    >>> lstYes.SelectionMode = ListSelectionMode.Multiple
    >>> lstNo.ID = "lstN" & drvTemp("UserID") 'Assuming ID is the part
    >>>
    >>>

    >we
    >
    >
    >>>want form the DB
    >>> lstNo.SelectionMode = ListSelectionMode.Multiple
    >>> lblName.Text = drvTemp("FullName")
    >>> 'Response.Write(drvTemp("FullName") & "<BR>")
    >>> For i As Integer = 0 To objItemType.Layout.Count() - 1
    >>> lstYes.Items.Add(objItemType.Layout.Item(i).Field.Caption())
    >>> lstYes.Items(i).Value =
    >>>
    >>>

    >>objItemType.Layout.Item(i).Field.FieldID
    >>
    >>
    >>> Next
    >>>
    >>>'Put raw HTML into the Label control to build the 4 button table to move
    >>>items between the list boxes.
    >>>'To switch the items between listboxes
    >>>'onclick="SwitchList(document.getElementById('lstNotifyAvailable'),
    >>>
    >>>
    >>>

    >document.getElementById('lstNotifySelected'));AdNotify(document.getElementBy
    >
    >
    >>>Id('lstNotifyAvailable'));
    >>> With lblButtons
    >>> Text = "<table>"
    >>> .Text &= "<tr><td>"
    >>> .Text &= "<input type=""button"" class=""BoxType42""
    >>>value=""Allow All"" name=""btn" & drvTemp("UserID") & "AA""
    >>>onclick=""SwitchList(document.getElementById('" & lstYes.ID.ToString &
    >>>
    >>>

    >>"'),
    >>
    >>
    >>> document.getElementById ('" & lstNo.ID.ToString &
    >>>"'));AddNotify(document.getElementById('" & lstYes.ID.ToString() &
    >>>
    >>>

    >>"'));"">"
    >>
    >>
    >>> .Text &= "</td></tr>"
    >>> .Text &= "<tr><td>"
    >>> .Text &= "<input type=""button"" class=""BoxType42""
    >>>value=""Allow"" name=""btn" & drvTemp("UserID") & "A""
    >>>onclick=""Allow(document.Security." & lstYes.ID.ToString() &
    >>>",document.Security." & lstNo.ID.ToString() & ");"">"
    >>> .Text &= "</td></tr>"
    >>> .Text &= "<tr><td>"
    >>> .Text &= "<input type=""button"" class=""BoxType42""
    >>>value=""Disallow All"" name=""btn" & drvTemp("UserID") & "DA""
    >>>onclick=""DisAll(document.Security." & lstYes.ID.ToString() &
    >>>",document.Security." &
    >>> lstNo.ID.ToString() & ");"">"
    >>> .Text &= "</td></tr>"
    >>> .Text &= "<tr><td>"
    >>> .Text &= "<input type=""button"" class=""BoxType42""
    >>>value=""Disallow"" name=""btn" & drvTemp("UserID") & "D""
    >>>onclick=""Disallow(document.Security." & lstYes.ID.ToString() &
    >>>",document.Security." &
    >>> lstNo.ID.ToString() & ");"">"
    >>> .Text &= "</td></tr>"
    >>> .Text &= "</table>"
    >>> End With
    >>>
    >>> Catch ex As Exception
    >>> Debug.WriteLine(ex.ToString)
    >>> Response.Write("<BR>_______________________<BR>" & ex.ToString &
    >>>"<BR>")
    >>> Response.Flush()
    >>> End Try
    >>>
    >>>End If
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
    >
    >
     
    Shan Plourde, Jul 23, 2004
    #4
  5. Ryan Ternier

    Teemu Keiski Guest

    You don't need to do those replaces at all if you'd use ClientID property
    instead of UniqueID...

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


    "Shan Plourde" <> wrote in message
    news:9haMc.1163011$...
    > I've had to do this a few times. Here's a code snippet:
    > <a
    > href="javascript:eek:penWin('<%= tbCompanyName.UniqueID.Replace(":",
    > "_") %>', '<%= tbCompanyId.UniqueID.Replace(":", "_") %>')">Find</a>
    >
    > This code snippet calls a javascript function. Control.UniqueID gives
    > you the full name of a control
    > Shan Plourde
    >
    > Ryan Ternier wrote:
    >
    > >The issue i'm having is my repeater will be repeating multiple sets of 2
    > >list boxes.
    > >
    > >I'm using client side JS to move items from 1 listbox to the other, for

    each
    > >repeating.
    > >
    > >I didn't know you could grab the ClientID property... i'll have to look

    into
    > >that, and see if I can get that to work.
    > >
    > >Thanks!
    > >"Teemu Keiski" <> wrote in message
    > >news:...
    > >
    > >
    > >>Hi,
    > >>
    > >>no there isn't. ASP.NET gives controls the IDs based on their location

    in
    > >>control hierarchy and if control is contained in a naming container,

    which
    > >>RepeaterItem is, it is named in new scope (scope of the repeaterItem

    where
    > >>it is contained) and named according to that. This way it is ensured

    that
    > >>every control has unique ID on the Page.
    > >>
    > >>What's the issue with this? You can get reference to the control via the
    > >>RepeaterItem (callint RepeaterItem's FindControl method) and there you
    > >>
    > >>

    > >could
    > >
    > >
    > >>use plain ID (lstYes14). If you need the ID at client-side, you can get

    it
    > >>with controls ClientID property which returns the unique ID as
    > >>clientscript-friendly. Also you can locate the control from top-level
    > >>control (outside the Repeater) by using Page.FindControl and assigning

    the
    > >>complete unique ID string, though seems that you are not looking for

    that.
    > >>
    > >>--
    > >>Teemu Keiski
    > >>MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > >>ASP.NET Forum Moderator, AspAlliance Columnist
    > >>http://blogs.aspadvice.com/joteke
    > >>
    > >>
    > >>
    > >>"Ryan Ternier" <> wrote in message
    > >>news:...
    > >>
    > >>
    > >>>Hello,
    > >>>
    > >>>I have a repeater control that does the following on the ItemDataBound
    > >>>event. It works perfectly, except that when it prints out, the names

    of
    > >>>
    > >>>
    > >>the
    > >>
    > >>
    > >>>controls
    > >>>aren't what I'd expect.
    > >>>
    > >>>lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part we want
    > >>>
    > >>>
    > >>form
    > >>
    > >>
    > >>>the DB
    > >>>
    > >>>I use that to set the ID of the listBox, but when it comes to the

    screen
    > >>>
    > >>>
    > >>it
    > >>
    > >>
    > >>>has a name of
    > >>>
    > >>>rptSecurity:ctrl00:lstYes14
    > >>>
    > >>>Or something similar to that.
    > >>>
    > >>>Is there a way to make that control just have lstYes14?
    > >>>
    > >>>
    > >>>If Not e.Item.DataItem Is Nothing Then
    > >>> Try
    > >>> Dim intTypeID = CInt(Request.QueryString.Get("TypeID"))
    > >>> Dim objItemType As ItemType
    > >>> objItemType = New ItemType(CInt(intTypeID))
    > >>>
    > >>> 'Get the current item that's being bound from the DB
    > >>> Dim drvTemp As DataRowView = CType(e.Item.DataItem,

    DataRowView)
    > >>> 'Get handles on the server side controls so we can edit them
    > >>>
    > >>>
    > >>through
    > >>
    > >>
    > >>>code. l337 pwn4g3
    > >>> Dim lstYes As ListBox = CType(e.Item.FindControl("listYes"),
    > >>>ListBox)
    > >>> Dim lstNo As ListBox = CType(e.Item.FindControl("listNo"),
    > >>>
    > >>>
    > >>ListBox)
    > >>
    > >>
    > >>> Dim lblButtons As Label =
    > >>>
    > >>>
    > >>CType(e.Item.FindControl("LabelButtons"),
    > >>
    > >>
    > >>>Label)
    > >>> Dim lblName As Label = CType(e.Item.FindControl("LabelName"),
    > >>>
    > >>>
    > >>Label)
    > >>
    > >>
    > >>> lstYes.ID = "lstY" & drvTemp("UserID") 'Assuming ID is the part
    > >>>
    > >>>

    > >we
    > >
    > >
    > >>>want form the DB
    > >>> lstYes.SelectionMode = ListSelectionMode.Multiple
    > >>> lstNo.ID = "lstN" & drvTemp("UserID") 'Assuming ID is the part
    > >>>
    > >>>

    > >we
    > >
    > >
    > >>>want form the DB
    > >>> lstNo.SelectionMode = ListSelectionMode.Multiple
    > >>> lblName.Text = drvTemp("FullName")
    > >>> 'Response.Write(drvTemp("FullName") & "<BR>")
    > >>> For i As Integer = 0 To objItemType.Layout.Count() - 1
    > >>>

    lstYes.Items.Add(objItemType.Layout.Item(i).Field.Caption())
    > >>> lstYes.Items(i).Value =
    > >>>
    > >>>
    > >>objItemType.Layout.Item(i).Field.FieldID
    > >>
    > >>
    > >>> Next
    > >>>
    > >>>'Put raw HTML into the Label control to build the 4 button table to

    move
    > >>>items between the list boxes.
    > >>>'To switch the items between listboxes
    > >>>'onclick="SwitchList(document.getElementById('lstNotifyAvailable'),
    > >>>
    > >>>
    > >>>

    >
    >document.getElementById('lstNotifySelected'));AdNotify(document.getElementB

    y
    > >
    > >
    > >>>Id('lstNotifyAvailable'));
    > >>> With lblButtons
    > >>> Text = "<table>"
    > >>> .Text &= "<tr><td>"
    > >>> .Text &= "<input type=""button"" class=""BoxType42""
    > >>>value=""Allow All"" name=""btn" & drvTemp("UserID") & "AA""
    > >>>onclick=""SwitchList(document.getElementById('" & lstYes.ID.ToString &
    > >>>
    > >>>
    > >>"'),
    > >>
    > >>
    > >>> document.getElementById ('" & lstNo.ID.ToString &
    > >>>"'));AddNotify(document.getElementById('" & lstYes.ID.ToString() &
    > >>>
    > >>>
    > >>"'));"">"
    > >>
    > >>
    > >>> .Text &= "</td></tr>"
    > >>> .Text &= "<tr><td>"
    > >>> .Text &= "<input type=""button"" class=""BoxType42""
    > >>>value=""Allow"" name=""btn" & drvTemp("UserID") & "A""
    > >>>onclick=""Allow(document.Security." & lstYes.ID.ToString() &
    > >>>",document.Security." & lstNo.ID.ToString() & ");"">"
    > >>> .Text &= "</td></tr>"
    > >>> .Text &= "<tr><td>"
    > >>> .Text &= "<input type=""button"" class=""BoxType42""
    > >>>value=""Disallow All"" name=""btn" & drvTemp("UserID") & "DA""
    > >>>onclick=""DisAll(document.Security." & lstYes.ID.ToString() &
    > >>>",document.Security." &
    > >>> lstNo.ID.ToString() & ");"">"
    > >>> .Text &= "</td></tr>"
    > >>> .Text &= "<tr><td>"
    > >>> .Text &= "<input type=""button"" class=""BoxType42""
    > >>>value=""Disallow"" name=""btn" & drvTemp("UserID") & "D""
    > >>>onclick=""Disallow(document.Security." & lstYes.ID.ToString() &
    > >>>",document.Security." &
    > >>> lstNo.ID.ToString() & ");"">"
    > >>> .Text &= "</td></tr>"
    > >>> .Text &= "</table>"
    > >>> End With
    > >>>
    > >>> Catch ex As Exception
    > >>> Debug.WriteLine(ex.ToString)
    > >>> Response.Write("<BR>_______________________<BR>" & ex.ToString

    &
    > >>>"<BR>")
    > >>> Response.Flush()
    > >>> End Try
    > >>>
    > >>>End If
    > >>>
    > >>>
    > >>>
    > >>>
    > >>
    > >>

    > >
    > >
    > >
    > >

    >
     
    Teemu Keiski, Jul 24, 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. Jorge Ayala

    handling buttons within repeater control

    Jorge Ayala, Nov 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,473
    Adrijan Josic
    Nov 19, 2003
  2. Darren Smith
    Replies:
    5
    Views:
    5,528
    dsmith
    May 10, 2004
  3. Replies:
    0
    Views:
    861
  4. Brian Miller
    Replies:
    6
    Views:
    708
    Brian Miller
    Nov 18, 2004
  5. Jaime Stuardo

    How to access a server control within a repeater control

    Jaime Stuardo, Aug 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    170
    Jaime Stuardo
    Aug 19, 2006
Loading...

Share This Page