Triggering UpdatePanel PostBack from within Nested UserControl

Last post 05-15-2008 9:34 AM by Dollarjunkie. 9 replies.

Sort Posts:

  • Triggering UpdatePanel PostBack from within Nested UserControl

    05-13-2008, 1:14 PM
    I have a UserControl B, embedded in UserControl A. I also have an UpdatePanel in my UserControl A called SmartUpdatePanel. What I want to do is When Button in Control B is clicked and the operation was successful, programmatically or automatically trigger a postBack on the SmartUpdatePanl contained in Control A. How do I accomplish this please? Thanks in Advance

     

    .Net Web/Software Engineer
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-13-2008, 2:46 PM

     So far, I have been able to do this to reach the Button Control that I need to fire to refresh the UpdatePanel.. I am not sure if this is the best way to do it. Another issue is When I raise the click event, nothing happens

     

                   'programmatically call UpdatePanel in Display DataList
                    Dim coCollection As Control
                    For Each coCollection In Me.Page.Controls
                        If coCollection.ID = "form1" Then 'Form on the Default.aspx page
                            Dim a As Control = coCollection.FindControl("SmartArea") 'Div Control on the Default.aspx page
                            If Not a Is Nothing Then
                                ' Find the UpdatePanel contained within
                                Dim CUpdate As UpdatePanel = CType(a.FindControl("UpdatePanel1"), UpdatePanel)
                                If Not CUpdate Is Nothing Then
                                    'Find the button inside of it
                                    Dim b As Button = CType(CUpdate.FindControl("BtnUpdate"), Button)
                                    If Not b Is Nothing Then
                                        'programmatically click the Button to fire the event
                                        CType(b, IPostBackEventHandler).RaisePostBackEvent(Nothing)
                                    End If
                                End If
                            End If
                        End If
                    Next
                End If

    .Net Web/Software Engineer
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-13-2008, 2:58 PM
    • Loading...
    • mohsinaeem
    • Joined on 05-08-2008, 7:41 AM
    • Lahore, Pakistan
    • Posts 13

    I think if you simple use the <UpdatePanelID>.Update() to update the update panel. But I don't know the exact scenario why you want to postback. If purpose to postback is only to update the panel than you need to update the panel using Update() method of the update panel. 

    Mohsin Naeem
    MCPD
    eWorx International
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-13-2008, 3:12 PM

    mohsinaeem:

    I think if you simple use the <UpdatePanelID>.Update() to update the update panel. But I don't know the exact scenario why you want to postback. If purpose to postback is only to update the panel than you need to update the panel using Update() method of the update panel. 

     

     

    I did try that but that did not cause a postback either. I have a Datalist control in the Parent UserControl and then I have another UserControl embedded in the FooterTemplate of the first UserControl. What I want to have happen is when User adds data to the Form UserControl in the FooterTemplate of the Parent UserControl, and then clicks the Add button, the Update Control Containing the Parent Usercontrol should update. So far, I am yet to accomplish this.  

    .Net Web/Software Engineer
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-13-2008, 4:12 PM
    • Loading...
    • mohsinaeem
    • Joined on 05-08-2008, 7:41 AM
    • Lahore, Pakistan
    • Posts 13

    Try to place the following trigger into your update panel to whom you want to postback. <asp:AsyncPostBackTrigger ControlID="<usercontrolid>$<buttonid>" />. Because I already working on that kind of scenario. I try to use triggers to update the different panels. Because in the above trigger we're setting the trigger of one usercontrol button into another.

    Mohsin Naeem
    MCPD
    eWorx International
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-14-2008, 9:52 AM

     

    At runtime, when I access the button information, the ID of the button is in the order below

     

    ParentUserControlID_DataListControlID_ctl23_ChildUserControlID_ButtonID .

     

    Since all the controls in this hierarchy are contained the the updatepanel control, UpdatePanel1,

    How would I go about referencing the button to cause the updatepanel to fire when it is clicked? Is it as below?

     

     <asp:AsyncPostBackTrigger ControlID="< ParentUserControlID >$< DataListControlID >$<ctl23>< ChildUserControlID>$<ButtonID>"/>

     

    .Net Web/Software Engineer
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-14-2008, 10:10 AM

     

     

    I also have to add that I am adding the UpdatePanel Programmatically as well. Just to let you know, what I have now, actually does call the Updatepanel control’s

    Update() method but the problem is the update or refreshing of the portion of the page itself does not seem to occur even after this.

     

       Dim coCollection As Control

                    For Each coCollection In Me.Page.Controls

                        If coCollection.ID = "form1" Then 'Form on the Default.aspx page

                            Dim a As Control = coCollection.FindControl("SmartArea") 'Div Control on the Default.aspx page

                            If Not a Is Nothing Then

                                ' Find the UpdatePanel contained within

                                Dim CUpdate As UpdatePanel = CType(a.FindControl("UpdatePanel1"), UpdatePanel)

                                If Not CUpdate Is Nothing Then

                                    'Find the button inside of it

                                    CUpdate.Update()

                                    'Dim b As Button = CType(CUpdate.FindControl("BtnUpdate"), Button)

                                    'If Not b Is Nothing Then

                                    '    'programmatically click the Button to fire the event

                                    '    CType(b, IPostBackEventHandler).RaisePostBackEvent(Nothing)

                                    'End If

                                End If

                            End If

                        End If

                    Next

                End If

     

    .Net Web/Software Engineer
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-14-2008, 2:12 PM
    • Loading...
    • mohsinaeem
    • Joined on 05-08-2008, 7:41 AM
    • Lahore, Pakistan
    • Posts 13

    The control id you wrote in the last line is fine to set the control to trigger. Event is automatically working you only need to set the control id. I already implment that kind of scenario. That's why I'm sure control working fine with control id that contains $ sign not under score( _ ).

    Mohsin Naeem
    MCPD
    eWorx International
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-14-2008, 4:54 PM

    How do I then add this dynamically?? I mean right now this is the way I add my UpdatePanel control ..

     

    Dim UpdatePanelControl As UpdatePanel = New UpdatePanel

    UpdatePanelControl.ID = "UpdatePanel1"

    UpdatePanelControl.UpdateMode = UpdatePanelUpdateMode.Conditional

    UpdatePanelControl.ChildrenAsTriggers = True

     

     

    How then do I go about adding that specific control as trigger??

    .Net Web/Software Engineer
  • Re: Triggering UpdatePanel PostBack from within Nested UserControl

    05-15-2008, 9:34 AM
    Answer

    I finally got it working. I went ahead and placed a Button within the same UpdatePanel, hooked it up with a click event in which I called back the code that loaded my UpdatePanel Control. I then set the UpdatePanel control UpdateMode property to ALWAYS. In my UserControl, I then would fire the click event of the Button control and the code would execute and cause my Updatepanel to refresh. Thanks

    .Net Web/Software Engineer
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter