locked
How to register UpdatePanel inside UserControl with ScriptManager on Master page? RRS feed

  • Question

  • User-1818008519 posted

    Hi,

    First of all there is a lot of missing functionality from Microsoft.Web.Atlas.dll to Microsoft.Web.Extenstions.dll as soon as you add the DLL to Toolbox you will see WebPartManager, UpdateProgress is missing for example. Is this planned in next releases or I'm missing something?

    When I just replace September Release with October Release by following the migration steps and changing the Web.config, below code throws this:

    Cannot unregister UpdatePanel with ID 'UpdateDatePanel' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported.

    [ArgumentException: Cannot unregister UpdatePanel with ID 'UpdateDatePanel' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported.
    Parameter name: updatePanel]
       Microsoft.Web.UI.PageRequestManager.UnregisterUpdatePanel(UpdatePanel updatePanel) +215
       Microsoft.Web.UI.ScriptManager.Microsoft.Web.UI.IScriptManagerInternal.UnregisterUpdatePanel(UpdatePanel updatePanel) +68
       Microsoft.Web.UI.UpdatePanel.OnUnload(EventArgs e) +67
       System.Web.UI.Control.UnloadRecursive(Boolean dispose) +284
       System.Web.UI.Control.UnloadRecursive(Boolean dispose) +221

    Is there any chance of supporting dynamic controls with update panels?

    Master Page:

            <asp:ScriptManager id="MasterScriptManager" runat="server" EnablePartialRendering="true">
            </asp:ScriptManager>
            <table id="maincontent" border="0" cellpadding="0" cellspacing="5" width="850">
                <tr valign="top">
                    <td>
                        <table class="leftcolumn" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <td id="leftcontent">
                                    <asp:ContentPlaceHolder ID="LeftContentHolder" runat="server">
                                    </asp:ContentPlaceHolder>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table class="middlecolumn" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <td id="middlecontent">
                                    <asp:ContentPlaceHolder ID="MiddleContentHolder" runat="server">
                                    </asp:ContentPlaceHolder>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table class="rightcolumn" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <td id="rightcontent" valign="top">
                                    <asp:ContentPlaceHolder ID="RightContentHolder" runat="server">
                                    </asp:ContentPlaceHolder>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
     </table>

    Content Page:

    <asp:Content ID="LeftContent" ContentPlaceHolderID="LeftContentHolder" Runat="Server">

    <asp:PlaceHolder id="LeftPlaceHolder" runat="server"/>

    </asp:Content>

    <asp:Content ID="MiddleContent" ContentPlaceHolderID="MiddleContentHolder" Runat="Server">

    <asp:PlaceHolder id="MiddlePlaceHolder" runat="server"/>

    </asp:Content>

    <asp:Content ID="RightContent" ContentPlaceHolderID="RightContentHolder" Runat="Server">

    <asp:PlaceHolder id="RightPlaceHolder" runat="server"/>

    </asp:Content>

    ContentPage.cs inside Page_Load:

    Initialize the controls dynamically with LoadControl 

    LeftPlaceHolder.Controls.Clear();

    foreach (UserControl uc in left)

    {

    if (uc != null)

    {

    LeftPlaceHolder.Controls.Add(uc);

    }

    }

    MiddlePlaceHolder.Controls.Clear();

    foreach (UserControl uc in middle)

    {

    if (uc != null)

    {

    MiddlePlaceHolder.Controls.Add(uc);

    }

    }

    RightPlaceHolder.Controls.Clear();

    foreach (UserControl uc in right)

    {

    if (uc != null)

    {

    RightPlaceHolder.Controls.Add(uc);

    }

    }

    DateControl.ascx code loaded twice in the LeftPlaceHolder:

     

    <asp:Panel ID="DatePanel" runat="server" CssClass="popupControl">

    <asp:UpdatePanel ID="UpdateDatePanel" runat="server">

    <ContentTemplate>

    <center>

    <asp:Calendar ID="CalendarDate" runat="server"

    DayNameFormat="Shortest"

    Width="160px"

    OnSelectionChanged="CalendarDate_SelectionChanged"

    CssClass="AvailabilityCalendar" OnVisibleMonthChanged="CalendarDate_VisibleMonthChanged">

    <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />

    <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />

    <SelectorStyle BackColor="#CCCCCC" />

    <WeekendDayStyle BackColor="#FFFFCC" />

    <OtherMonthDayStyle ForeColor="#808080" />

    <NextPrevStyle VerticalAlign="Bottom" />

    <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />

    <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />

    </asp:Calendar>

    </center>

    </ContentTemplate>

    </asp:UpdatePanel>

    </asp:Panel>

    Thanks & Regards,

    C.

    Saturday, October 28, 2006 1:31 PM

Answers

  • User287763314 posted

    hello.

    regarding the missing components, those are now in the value-added bits and you must add them by hand to the toolbox:

    http://msmvps.com/blogs/luisabreu/archive/2006/10/23/How-to-add-the-value_2D00_added-controls-to-the-toolbox.aspx

    regarding the other problem, it's a known issue and has already been presented here. the problem is that the updatepanel registers itself with the  scriptmanager during preinit. when you remove the control from the collection (or another control which contains the updatepanel), the unload method will be automatically called and this will make the updatepanel to unregister itself with the scriptmanager control. when you re-add the some component, the init event won't be rerun because that event has already been run for that control and due to that the updatepanel won't be registered again with the scriptmanager control. however, during the unload phase, the onunload method will be called again and it's there you'll get the exception.

    the onyl workaround for rremoving and adding  controls dynamically is to do it until the end of the preinit event. doing after that event means you'll get the exception you're having.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 29, 2006 8:42 AM

All replies

  • User287763314 posted

    hello.

    regarding the missing components, those are now in the value-added bits and you must add them by hand to the toolbox:

    http://msmvps.com/blogs/luisabreu/archive/2006/10/23/How-to-add-the-value_2D00_added-controls-to-the-toolbox.aspx

    regarding the other problem, it's a known issue and has already been presented here. the problem is that the updatepanel registers itself with the  scriptmanager during preinit. when you remove the control from the collection (or another control which contains the updatepanel), the unload method will be automatically called and this will make the updatepanel to unregister itself with the scriptmanager control. when you re-add the some component, the init event won't be rerun because that event has already been run for that control and due to that the updatepanel won't be registered again with the scriptmanager control. however, during the unload phase, the onunload method will be called again and it's there you'll get the exception.

    the onyl workaround for rremoving and adding  controls dynamically is to do it until the end of the preinit event. doing after that event means you'll get the exception you're having.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 29, 2006 8:42 AM
  • User-1818008519 posted

    hi, Luis

    The controls like LeftContentHolder I have declared on the content page are not visible at that stage, so I would have to create those dynamically as well.

    The new Beta 1 reflects too many changes in my code so I will be waiting for the next release, otherwise most of the toolkit controls looks much better.

    Thanks & Regards,

    Constantin

    Sunday, October 29, 2006 6:47 PM
  • User287763314 posted

    hello.

    that's a fact: beta 1 is a complete different product than the previous ctps. the good thing about it is that after the 1st week, you're really appreciate the quality of these bits :) 

    Monday, October 30, 2006 6:15 AM
  • User890714724 posted

    I've looked through the javascript and have noticed that each update panel is registered (clientside) via:

    Sys.WebForms.PageRequestManager.getInstance()._updateControls this then manages the update panels client side and allows for async requests & triggers etc when handling postbacks via the PageRequestManager.

    In your post above when you mention the pre_init event are you refering to the server side event?  Are there any good resources for the inner workings both client side and server side? We're having a lot of problems when loading controls dynamically especially regarding script management and viewstate handling!

     

    Any help will be very much appreciated. 

     

     

     

     


     
     

    Wednesday, November 1, 2006 12:25 PM
  • User890714724 posted

    Strange thing! I've noticed that in my default.aspx page I am loading controls that contain updatepanels within the oninit event handler.

    These are added and removed without any issues how can this be working given what you have said? 

    Thursday, November 2, 2006 5:23 AM
  • User287763314 posted

    hello.

    i'm talking about the server side preinit event. note that you only need to do things in this event if you're removing an existing updatepanel from a collection and adding to another that exists on that page. if you're adding the controls dynamically, there's no need to do things on the preinit event.

    Thursday, November 2, 2006 5:37 AM
  • User890714724 posted

    Can you give an example - I'm a little lost.

    Are you saying that if I have an update panel and I remove it from one control collection and move it into another control collection, I have to do this in the server side pre-innit event? 

     

     

     

    Thursday, November 2, 2006 7:12 AM
  • User287763314 posted

    hello again.

    yes, that is correct. on the other hand, if you're creating a new updatepanel, then you can add it to the page without problems during the load event...

    i've already seen several examples where people use code to take a control from a control's collection and add it to another control's collection. if you're doing this, then it must be done till the end of the preinit event.

    Thursday, November 2, 2006 7:15 AM
  • User890714724 posted

    So the following has to be done in  pre_innit

    myObject1.controls.remove[myUpdatePanel];

    myObject2.controls.add[myUpdatePanel];

     
    BUT this is okay

    myObject1.controls.remove[myUpdatePanel];
    myObject1.controls.add[myUpdatePanel];

    As is this:

    myObject1.controls.remove[myUpdatePanel1];
    myObject2.controls.add[myUpdatePanel2];

    ???



     

    Thursday, November 2, 2006 7:24 AM
  • User287763314 posted

    hello.

    none of the ones you say OK are correct. the problem is not removing and adding to a different control. the problem is when you remove and add to any control.

    what is ok is if you do something like this:

    UpdatePanel p = new UpdatePanel();

    .,.more code here to configure updatepanel

    object.controls.add( p );

    this is ok and you can do it on the load event.
     

    Thursday, November 2, 2006 8:58 AM
  • User890714724 posted

    Thats strange because I have the following:

    myObject1.controls.remove[myUpdatePanel];
    myObject1.controls.add[myUpdatePanel];

     

    occurring in page_init through out my code and it works fine!! 

    Thursday, November 2, 2006 9:03 AM
  • User287763314 posted

    hello.

    i'll have to check that. can you post a small sample that illustrates the relationship between myobject1 and myupdatepanel?

    thanks. 

    Thursday, November 2, 2006 9:17 AM
  • User890714724 posted

    Right - so the 1st and 2nd shouldnt work BUT if the following case should be okay, because they are different update panels (myUpdatePanel1) and (myUpdatePanel2)  

     

    myObject1.controls.remove[myUpdatePanel1];
    myObject2.controls.add[myUpdatePanel2];

     

    ??? 

    Thursday, November 2, 2006 11:41 AM
  • User287763314 posted

    hello.

    what a mess...i'm already lost :)

     

    >So the following has to be done in  pre_innit

    >myObject1.controls.remove[myUpdatePanel];

    >myObject2.controls.add[myUpdatePanel];

    these should work in preinit 

     

     
    >BUT this is okay

    >myObject1.controls.remove[myUpdatePanel];
    >myObject1.controls.add[myUpdatePanel];

    i think this won't work if not done in preinit. however, you said it was ok, right?

     

    >As is this:

    >myObject1.controls.remove[myUpdatePanel1];
    >myObject2.controls.add[myUpdatePanel2];

    i'd say that this could work if you're not adding updatepanel2 again...

     

    Thursday, November 2, 2006 2:26 PM