+ Reply to Thread
Results 1 to 4 of 4

Thread: Reference User Control in nested repeater

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    303
    Rep Power
    3

    Reference User Control in nested repeater

    Hi again

    the scenario:
    my user control is loaded into a ModalPopupExtender via OnItemDataBound of
    a repeater sitting in the diaplay Panel of the ModalPopup.

    inside that panel is an update button which fires an event, which in turn fires
    an update event in my user control's code-behind.

    All of this is happening within a nested repeater (grandchild), and this is what
    makes it difficult to reference controls etc.

    here's my logic:
    the sender is the 'Update Button'
    from there I can reference the Panel the button resides in
    from there I can reference the Repeater that resides in the Panel.

    this all works, so from there I wanted to reference my UserControl that
    was in the repeater, but alas it doesn't find my UserControl.

    my code for the Update event of my Update Button:
    green = works
    red = doesn't work
    Code:
    Public Sub ActiveSpecificationsUpdate(ByVal sender As Object, ByVal e As EventArgs)
            Dim myButton As Button = sender
            Dim pnlActiveSpecification As Panel = myButton.Parent
            Dim rpActiveSpecification As Repeater = pnlActiveSpecification.FindControl("rpActiveSpecification")
            If CType(ViewState("FormsArt"), String) = "1" Then
                Dim FormsArt As CustomControls_form_art = rpActiveSpecification.FindControl("FormsArt")
                FormsArt.SpecID = myParams.SpecID
                FormsArt.Visible = True
                FormsArt.Update_Form()
                ViewState("FormsArt") = "0".ToString()
            End If
        End Sub
    
    any ideas?
    Shem

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    You will need to search through the repeater items to find your user control. If the user control is in the same repeater item as the button that you clicked:

    Code:
    Public Sub ActiveSpecificationsUpdate(ByVal sender As Object, ByVal e As EventArgs)
        Dim btn As Button = sender
        Dim FormsArt As CustomControls_form_art = btn.Parent.FindControl("FormsArt")
    End Sub
    
    Or, you can try iterating through the repeater items:

    Code:
    Public Sub ActiveSpecificationsUpdate(ByVal sender As Object, ByVal e As EventArgs)
        For Each item As RepeaterItem in Repeater1.Items
            Dim FormsArt As CustomControls_form_art = TryCast(item.FindControl("FormsArt"), CustomControls_form_art)
        Next
    End Sub
    
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    303
    Rep Power
    3

    You effing Genius.....

    this totally worked:
    Code:
    Public Sub ActiveSpecificationsUpdate(ByVal sender As Object, ByVal e As EventArgs)
        For Each item As RepeaterItem in Repeater1.Items
            Dim FormsArt As CustomControls_form_art = TryCast(item.FindControl("FormsArt"), CustomControls_form_art)
        Next
    End Sub
    
    Thanx alot dude, can't believe i only tried this now
    Shem

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    Cheers Glad I could help
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread

LinkBacks (?)


Similar Threads

  1. trying to reference my user controls properties?
    By Shem in forum .Net Development
    Replies: 3
    Last Post: October 3rd, 2008, 04:06 AM
  2. Replies: 11
    Last Post: October 2nd, 2008, 08:41 AM
  3. Object Reference Error on Custom Control Postback
    By richyrich in forum .Net Development
    Replies: 1
    Last Post: September 22nd, 2008, 05:56 PM
  4. reference control from nested repeater
    By Shem in forum .Net Development
    Replies: 18
    Last Post: September 15th, 2008, 10:46 AM
  5. paging enabled in a repeater control
    By peebman2000 in forum .Net Development
    Replies: 6
    Last Post: September 4th, 2008, 11:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO