+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Dynamically added user control, not getting it's values

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

    Dynamically added user control, not getting it's values

    Hi guys

    I have a aspx page ajax enabled and using update panels, ModalpopupExtenders
    and on one of my ModalPopupextenders either one or more user controls are
    called up into the displayed panel of the Modalpopup.

    It loads only the controls that are assigned, to do this I assign the controls via
    the repeaters OnItemDataBound event:
    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
                Dim pnlActiveSpecificationForms As Panel = e.Item.FindControl("pnlActiveSpecificationForms")
    
    
                ViewState("FormsArt") = "".ToString
                ViewState("FormsCarpetRug") = "".ToString
                ViewState("FormsAccessories") = "".ToString
                ViewState("FormsBedding") = "".ToString
                ViewState("FormsCasegoods") = "".ToString
                ViewState("FormsDrapery") = "".ToString
                ViewState("FormsFabric") = "".ToString
                ViewState("FormsLighting") = "".ToString
                ViewState("FormsMirrors") = "".ToString
                ViewState("FormsPillow") = "".ToString
                ViewState("FormsTrims") = "".ToString
                ViewState("FormsUpholstered") = "".ToString
                ViewState("FormsArchitectschedule") = "".ToString
    
                '---------------------------------------
                Select Case myForms.Name
                    Case "Art"
                        FormsArt = CType(LoadControl("~/CustomControls/FormControls/form_art.ascx"), ASP.customcontrols_formcontrols_form_art_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsArt)
                        FormsArt.SpecID = myParams.SpecID
                        ViewState("FormsArt") = "~/CustomControls/FormControls/form_art.ascx".ToString
                    Case "Carpet Rug"
                        FormsCarpetRug = CType(LoadControl("~/CustomControls/FormControls/form_carpetrug.ascx"), ASP.customcontrols_formcontrols_form_carpetrug_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsCarpetRug)
                        FormsCarpetRug.SpecID = myParams.SpecID
                        ViewState("FormsCarpetRug") = "~/CustomControls/FormControls/form_carpetrug.ascx".ToString
                    Case "Accessories"
                        FormsAccessories = CType(LoadControl("~/CustomControls/FormControls/form_accessories.ascx"), ASP.customcontrols_formcontrols_form_accessories_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsAccessories)
                        FormsAccessories.SpecID = myParams.SpecID
                        ViewState("FormsAccessories") = "~/CustomControls/FormControls/form_accessories.ascx".ToString
                    Case "Bedding"
                        FormsBedding = CType(LoadControl("~/CustomControls/FormControls/form_bedding.ascx"), ASP.customcontrols_formcontrols_form_bedding_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsBedding)
                        FormsBedding.SpecID = myParams.SpecID
                        ViewState("FormsBedding") = "~/CustomControls/FormControls/form_bedding.ascx".ToString
                    Case "Casegoods"
                        FormsCasegoods = CType(LoadControl("~/CustomControls/FormControls/form_casegoods.ascx"), ASP.customcontrols_formcontrols_form_casegoods_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsCasegoods)
                        FormsCasegoods.SpecID = myParams.SpecID
                        ViewState("FormsCasegoods") = "~/CustomControls/FormControls/form_casegoods.ascx".ToString
                    Case "Drapery"
                        FormsDrapery = CType(LoadControl("~/CustomControls/FormControls/form_drapery.ascx"), ASP.customcontrols_formcontrols_form_drapery_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsDrapery)
                        FormsDrapery.SpecID = myParams.SpecID
                        ViewState("FormsDrapery") = "~/CustomControls/FormControls/form_drapery.ascx".ToString
                    Case "Fabric"
                        FormsFabric = CType(LoadControl("~/CustomControls/FormControls/form_fabric.ascx"), ASP.customcontrols_formcontrols_form_fabric_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsFabric)
                        FormsFabric.SpecID = myParams.SpecID
                        ViewState("FormsFabric") = "~/CustomControls/FormControls/form_fabric.ascx".ToString
                    Case "Lighting"
                        FormsLighting = CType(LoadControl("~/CustomControls/FormControls/form_lighting.ascx"), ASP.customcontrols_formcontrols_form_lighting_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsLighting)
                        FormsLighting.SpecID = myParams.SpecID
                        ViewState("FormsLighting") = "~/CustomControls/FormControls/form_lighting.ascx".ToString
                    Case "Mirrors"
                        FormsMirrors = CType(LoadControl("~/CustomControls/FormControls/form_mirrors.ascx"), ASP.customcontrols_formcontrols_form_mirrors_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsMirrors)
                        FormsMirrors.SpecID = myParams.SpecID
                        ViewState("FormsMirrors") = "~/CustomControls/FormControls/form_mirrors.ascx".ToString
                    Case "Pillow"
                        FormsPillow = CType(LoadControl("~/CustomControls/FormControls/form_pillow.ascx"), ASP.customcontrols_formcontrols_form_pillow_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsPillow)
                        FormsPillow.SpecID = myParams.SpecID
                        ViewState("FormsPillow") = "~/CustomControls/FormControls/form_pillow.ascx".ToString
                    Case "Trims"
                        FormsTrims = CType(LoadControl("~/CustomControls/FormControls/form_trims.ascx"), ASP.customcontrols_formcontrols_form_trims_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsTrims)
                        FormsTrims.SpecID = myParams.SpecID
                        ViewState("FormsTrims") = "~/CustomControls/FormControls/form_trims.ascx".ToString
                    Case "Uplholstered"
                        FormsUpholstered = CType(LoadControl("~/CustomControls/FormControls/form_upholstereditems.ascx"), ASP.customcontrols_formcontrols_from_upholstereditems_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsUpholstered)
                        FormsUpholstered.SpecID = myParams.SpecID
                        ViewState("FormsUpholstered") = "~/CustomControls/FormControls/form_upholstereditems.ascx".ToString
                    Case "Architectural Schedule"
                        FormsArchitectschedule = CType(LoadControl("~/CustomControls/FormControls/form_architectschedule.ascx"), ASP.customcontrols_formcontrols_form_architectschedule_ascx)
                        pnlActiveSpecificationForms.Controls.Add(FormsArchitectschedule)
                        FormsArchitectschedule.SpecID = myParams.SpecID
                        ViewState("FormsArchitectschedule") = "~/CustomControls/FormControls/form_architectschedule.ascx".ToString
                End Select
            End If
        End Sub
    
    ok so now i have my user control to capture.
    when i hit my update button, which resides in the display panel of the
    ModalPopup, not in the user control, so when the update button is clicked
    I call another sub which reloads the control(this is due to the controls being dynamically added) and calls the update function of that control:
    Code:
    Public Sub btnActiveSpecificationUpdate_OnClick(ByVal s As Object, ByVal e As EventArgs)
            Dim myButton As Button = s
    
            '---------------------------------------
            'decalre 
            Dim pnlActiveSpecification As Panel = myButton.Parent
    
            If CType(ViewState("FormsArt"), String) > "" Then
                FormsArt = CType(LoadControl("~/CustomControls/FormControls/form_art.ascx"), ASP.customcontrols_formcontrols_form_art_ascx)
                FormsArt.Update_Form()
            End If
        End Sub
    
    and here is the update function of the user control:
    Code:
    Public Sub Update_Form()
            Dim myArt As Art = New Art
            Dim fieldlist As New ArrayList
    
            '---------------------------------------
            'get all data
            myArt = ArtManager.GetItem(SpecID)
    
            '---------------------------------------
            'check to see if something has been updated
            If txtArt_material.Text <> myArt.Material Then
                fieldlist.Add("material")
                myArt.Material = txtArt_material.Text
            End If
            If txtArt_colour.Text <> myArt.Colour Then
                fieldlist.Add("colour")
                myArt.Colour = txtArt_colour.Text
            End If
            If txtArt_supplierref.Text <> myArt.SupplierRef Then
                fieldlist.Add("supplierref")
                myArt.SupplierRef = txtArt_supplierref.Text
            End If
            If txtArt_finish.Text <> myArt.Finish Then
                fieldlist.Add("finish")
                myArt.Finish = txtArt_finish.Text
            End If
            If txtArt_width.Text <> myArt.Width Then
                fieldlist.Add("width")
                myArt.Width = txtArt_width.Text
            End If
            If txtArt_height.Text <> myArt.Height Then
                fieldlist.Add("height")
                myArt.Height = txtArt_height.Text
            End If
            If txtArt_framewidth.Text <> myArt.FrameWidth Then
                fieldlist.Add("framewidth")
                myArt.FrameWidth = txtArt_framewidth.Text
            End If
            If txtArt_innerframe.Text <> myArt.InnerFrame Then
                fieldlist.Add("innerframe")
                myArt.InnerFrame = txtArt_innerframe.Text
            End If
            If txtArt_glassthickness.Text <> myArt.GlassThickness Then
                fieldlist.Add("glassthickness")
                myArt.GlassThickness = txtArt_glassthickness.Text
            End If
            If txtArt_hangingrequirements.Text <> myArt.HangingRequirements Then
                fieldlist.Add("hangingrequirements")
                myArt.HangingRequirements = txtArt_hangingrequirements.Text
            End If
    
            myArt.SpecID = SpecID
    
            '---------------------------------------
            'check to see if any records need to be updated, if so, update them
            If Not fieldlist.Count = 0 Then
                ArtManager.Update(myArt)
                fieldlist.RemoveRange(0, fieldlist.Count)
            End If
        End Sub
    
    but nothing get's passed, all the input fields from the user control are empty?
    any ideas here?

    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

    I'm not even going to attempt to sort through all that code lol

    Keep in mind that ASP.net does not maintain the control tree of dynamically added controls. If you dynamically add a control, then you must maintain the viewstate. Every time the page is reloaded (postback, partial postback), you will have to grab the values from your viewstate.

    CodeProject: Retaining State for Dynamically Created Controls in ASP.NET applications. Free source code and programming 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.


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

    my problem i have is that i need to recreate the controls in the Page_load
    event.

    But i need to recreate and add the control to a panel that sits in a Grandchild
    repeater:
    Code:
    <asp:Panel ID="pnlActiveContent" runat="server" CssClass="collapsePanel">
    	<asp:Repeater id="rpActiveCategory" runat="server" OnItemDataBound="rpActiveCategory_OnItemDataBound">
    		<asp:Panel ID="pnlActiveCategoryContent" runat="server" Visible="false">
    			<asp:Repeater id="rpActiveSubCategory" runat="server" OnItemDataBound="rpActiveSubCategory_OnItemDataBound">
    				<asp:Panel ID="pnlActiveSubCategoryContent" runat="server" height="100%" CssClass="collapsePanel">
    					<asp:Repeater ID="rpActiveSpecs" runat="server" OnItemDataBound="rpActiveSpecs_OnItemDataBound" OnItemCommand="rpActiveSpecs_OnItemCommand">
    						<asp:Panel ID="pnlActiveSpecification" runat="server" CssClass="modalPopup" style="display:none;">
    
    'pnlActiveSpecification' is the panel that they must be added to.
    'pnlActiveSpecification' is the display panel for a ModalPopupExtender.

    any ideas?
    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

    Are you still having problems with retaining values after update or is your problem now adding the control to the panel inside the nested repeater?
    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.


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

    after a lot of research and reading yesterday, I first need to reload the control
    before i can get the results, so until i'm able to reload my control, i guess i will
    not ever get or retain any values.

  6. #6
    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

    Quote Originally Posted by Shem View Post
    after a lot of research and reading yesterday, I first need to reload the control
    before i can get the results, so until i'm able to reload my control, i guess i will
    not ever get or retain any values.
    I guess what my real question is...why do you need to add the control programmatically? Can't you just stick it inside the repeater in design view and run it that way? By doing so, ASP.net will maintain the viewstate of the control.
    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.


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

    I have 12 different user controls, each of these capture diff data.
    each subcategory will get either one or more of these user controls assigned
    to it, so I can't stick all of them inside my repeater, unless I write a 'If Else'
    statement inside my repeater on the aspx page, which i suppose i could do?

  8. #8
    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

    Quote Originally Posted by Shem View Post
    I have 12 different user controls, each of these capture diff data.
    each subcategory will get either one or more of these user controls assigned
    to it, so I can't stick all of them inside my repeater, unless I write a 'If Else'
    statement inside my repeater on the aspx page, which i suppose i could do?
    You could always do it within the control's .ascx.vb page (i.e. build one control and use conditional to display the appropriate parts). OR you could do it in the repeater ItemDataBound event.
    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.


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

    currently I am loading the controls in the repeaters OnItemDataBound
    Quote Originally Posted by Shem
    It loads only the controls that are assigned, to do this I assign the controls via
    the repeaters OnItemDataBound event:
    And the page loading the controls is also a user control, sitting on a aspx page.

  10. #10
    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

    Right...what I meant was either place all of the user controls in the repeater, then on ItemDataBound, set the visibility of the appropriate control.

    However, if you build just one control to perform the functionality of all the controls you're trying to load, then you can just run a conditional inside the .vb file for that control instead of setting the visibility of all the controls during ItemDataBound.
    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
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Dynamically Linked Drop-Down Boxes
    By Rebelle in forum JavaScript Programming
    Replies: 4
    Last Post: September 26th, 2008, 12:00 PM
  2. update gridview dynamically
    By peebman2000 in forum .Net Development
    Replies: 27
    Last Post: May 8th, 2008, 10:03 PM
  3. User Title Suggestions
    By jmurrayhead in forum Suggestions & Feedback
    Replies: 15
    Last Post: March 21st, 2008, 12: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