+ Reply to Thread
Results 1 to 4 of 4

Thread: trying to reference my user controls properties?

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

    trying to reference my user controls properties?

    Hi

    I have a user control in a repeater.
    in my repeaters OnItemDataBound event, i check to see if I must
    set the control to be visible, and at the same time need to set a property
    of that control, which I can only do in the code-behind

    my repeater and user control:
    Code:
    <asp:Repeater ID="rpActiveSpecification" runat="server">
                                                                                    <ItemTemplate>
                                                                                        <tr>
                                                                                            <td>
                                                                                                <asp:Panel ID="pnlActiveSpecificationForms" runat="server">
                                                                                                    <forms:art ID="FormsArt" runat="server" Visible="false" />
                                                                                                </asp:Panel>
                                                                                            </td>
                                                                                        </tr>
                                                                                    </ItemTemplate>
                                                                                </asp:Repeater>
    
    my OnItemDataBound: (red)
    Code:
    Protected Sub rpActiveSpecification_OnItemDataBound(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                '---------------------------------------
                Dim myForms As Forms = e.Item.DataItem
    
                '---------------------------------------
                Select Case myForms.Name
                    Case "Art"
                        Dim FormsArt As UserControl = e.Item.FindControl("FormsArt")
                    Case "Carpet Rug"
                       
                    Case "Accessories"
                        
                    Case "Bedding"
                        
                    Case "Casegoods"
                       
                    Case "Drapery"
                        
                    Case "Fabric"
                        
                    Case "Lighting"
                       
                    Case "Mirrors"
                        
                    Case "Pillow"
                        
                    Case "Trims"
                        
                    Case "Uplholstered"
                        
                    Case "Architectural Schedule"
                       
                End Select
            End If
        End Sub
    
    The property i'm trying to set is 'SpecID'.
    when i loaded the controls dynamically I could set the property?

    My user controls are all registered in my web.config.

    Shem

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    I assume your user control inherits from the UserControl class; in which case you will need to cast the object returned from the FindControl method to your user control class rather than the UserControl class. That should make your property visible.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

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

    Hi Wolfy

    I think I understand what your saying, this is what i have now:
    Code:
    Dim FormsArt As CustomControls_form_art = e.Item.FindControl("FormsArt")
    FormsArt.SpecID = myParams.SpecID
    FormsArt.Visible = True
    
    This way does see my property SpecID.
    'CustomControls_form_art' is my controls Class name.

    Shem

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

    it seems to be working now Wolfy

+ Reply to Thread

Similar Threads

  1. Replies: 4
    Last Post: September 22nd, 2008, 11:55 AM
  2. Accessing controls in the Footer of a datalist
    By richyrich in forum .NET Development
    Replies: 6
    Last Post: May 12th, 2008, 01:19 PM
  3. User Title Suggestions
    By jmurrayhead in forum Community Support, Suggestions & Feedback
    Replies: 15
    Last Post: March 21st, 2008, 01:54 PM

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