UpdatePanel is doing full postback when it should not

Discussion in 'ASP .Net Web Controls' started by TomK, Feb 5, 2008.

  1. TomK

    TomK Guest

    I have a ASP.NET 2.0 web application that was written using traditional
    postbacks.
    I am in the process of Ajaxifying some pages.

    PROBLEM: Update panel is always causing postbacks

    I have 1 test page that does partial postbacks no problem. The second page
    is a legacy page that I have wrapped some controls in UpdatePanels and
    followed a similar model as the working test page. Whenever the UpdatePanel
    trigger is fired I keep getting full postbacks even though I have
    EnablePartialRendering=true.

    I know it has to be something at the page level since the test page works
    fine.

    Here are some sample snippets:

    <asp:ScriptManager runat="server" ID="ctlScriptManager"
    EnablePartialRendering="true" >
    </asp:ScriptManager>
    <script type="text/javascript" language="javascript">
    try
    {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_beginRequest(doNothing);
    prm.add_pageLoading(doNothing);
    prm.add_pageLoaded(doNothing);
    prm.add_endRequest(EndRequest);
    }catch(e)
    {
    //alert("There was an error setting up ScriptManager");
    }

    function InitializeRequest(sender, args)
    {

    alert('InitializeRequest');
    debugger
    if (prm.get_isInAsyncPostBack())
    {
    alert('cancelled double request');
    args.set_cancel(true);
    }else
    {
    if (!OnSubmitValidation())
    {
    alert('handled validation error');
    args.set_cancel(true);
    prm._originalDoPostBack(args._postBackElement.id,'');
    }
    }
    }

    function doNothing(sender, args)
    {
    }

    function EndRequest(sender, args)
    {
    DisableOnSubmitValidation();

    // TODO: handle timeout errors, and revert to fullpage postback
    if (args.get_error() && args.get_response().get_timedOut())
    {
    prm._originalDoPostBack(args._postBackElement.id,'');
    //alert('handled time out');
    args.set_errorHandled(true);
    }
    }
    </script>

    THIS IS THE TRIGGER CONTROL
    <asp:DropDownList ID="ddlCategory" alt="Category" runat="server"
    Width="100%" CssClass="clsDropDown" AutoPostBack="true">

    </asp:DropDownList>

    <asp:UpdatePanel runat="server"
    ID="updPnlCaseType" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:DropDownList ID="ddlCaseType"
    alt="Case Type" runat="server"
    Width="100%" CssClass="clsDropDown"
    AutoPostBack="True">
    </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlCategory"
    EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>

    <asp:UpdatePanel runat="server" ID="updPnlLocation" UpdateMode="Conditional">
    <ContentTemplate>
    <table><tr>
    <td class="clstd" style="width: 10%; vertical-align: top;">
    <div id="divLocationLabel" runat="server">Location:</div>
    </td>
    <td class="clstd" style="width: 700px">
    <div id="divLocation" runat="server">
    <ctrllocation:location ID="LocationControlCase"
    runat="server"
    SelectedLocation="All">
    </ctrllocation:location>
    </div>
    </td>
    </tr></table>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlCaseType"
    EventName="SelectedIndexChanged" />
    <asp:AsyncPostBackTrigger ControlID="ddlCategory"
    EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>

    <asp:UpdatePanel runat="server" ID="updPnlUDEFs" UpdateMode="always">
    <ContentTemplate>
    <ctrlUserDefinedFields:UserDefinedFields
    ID="ucCaseSubmissionFields" runat="server" />
    </ContentTemplate>
    </asp:UpdatePanel>

    Tom
     
    TomK, Feb 5, 2008
    #1
    1. Advertising

  2. TomK

    Harry Keck Guest

    When you say the whole page is posting back, do you mean that it is doing the
    "flicker" kind of postback where the entire page is re-rendered? If so, then
    yes, you do have a problem, but I can not tell anything wrong with the code
    you supplied.

    If, however, you simply mean that all of your server side code is running
    everytime an updatepanel updates, then that is correct behavior. When and
    AJAX page posts back, all of the server side code runs just as if partial
    rendering were not enabled. The only difference is that the client will only
    re-paint the portions marked for update.

    "TomK" wrote:

    > I have a ASP.NET 2.0 web application that was written using traditional
    > postbacks.
    > I am in the process of Ajaxifying some pages.
    >
    > PROBLEM: Update panel is always causing postbacks
    >
    > I have 1 test page that does partial postbacks no problem. The second page
    > is a legacy page that I have wrapped some controls in UpdatePanels and
    > followed a similar model as the working test page. Whenever the UpdatePanel
    > trigger is fired I keep getting full postbacks even though I have
    > EnablePartialRendering=true.
    >
    > I know it has to be something at the page level since the test page works
    > fine.
    >
    > Here are some sample snippets:
    >
    > <asp:ScriptManager runat="server" ID="ctlScriptManager"
    > EnablePartialRendering="true" >
    > </asp:ScriptManager>
    > <script type="text/javascript" language="javascript">
    > try
    > {
    > var prm = Sys.WebForms.PageRequestManager.getInstance();
    > prm.add_initializeRequest(InitializeRequest);
    > prm.add_beginRequest(doNothing);
    > prm.add_pageLoading(doNothing);
    > prm.add_pageLoaded(doNothing);
    > prm.add_endRequest(EndRequest);
    > }catch(e)
    > {
    > //alert("There was an error setting up ScriptManager");
    > }
    >
    > function InitializeRequest(sender, args)
    > {
    >
    > alert('InitializeRequest');
    > debugger
    > if (prm.get_isInAsyncPostBack())
    > {
    > alert('cancelled double request');
    > args.set_cancel(true);
    > }else
    > {
    > if (!OnSubmitValidation())
    > {
    > alert('handled validation error');
    > args.set_cancel(true);
    > prm._originalDoPostBack(args._postBackElement.id,'');
    > }
    > }
    > }
    >
    > function doNothing(sender, args)
    > {
    > }
    >
    > function EndRequest(sender, args)
    > {
    > DisableOnSubmitValidation();
    >
    > // TODO: handle timeout errors, and revert to fullpage postback
    > if (args.get_error() && args.get_response().get_timedOut())
    > {
    > prm._originalDoPostBack(args._postBackElement.id,'');
    > //alert('handled time out');
    > args.set_errorHandled(true);
    > }
    > }
    > </script>
    >
    > THIS IS THE TRIGGER CONTROL
    > <asp:DropDownList ID="ddlCategory" alt="Category" runat="server"
    > Width="100%" CssClass="clsDropDown" AutoPostBack="true">
    >
    > </asp:DropDownList>
    >
    > <asp:UpdatePanel runat="server"
    > ID="updPnlCaseType" UpdateMode="Conditional">
    > <ContentTemplate>
    > <asp:DropDownList ID="ddlCaseType"
    > alt="Case Type" runat="server"
    > Width="100%" CssClass="clsDropDown"
    > AutoPostBack="True">
    > </asp:DropDownList>
    > </ContentTemplate>
    > <Triggers>
    > <asp:AsyncPostBackTrigger ControlID="ddlCategory"
    > EventName="SelectedIndexChanged" />
    > </Triggers>
    > </asp:UpdatePanel>
    >
    > <asp:UpdatePanel runat="server" ID="updPnlLocation" UpdateMode="Conditional">
    > <ContentTemplate>
    > <table><tr>
    > <td class="clstd" style="width: 10%; vertical-align: top;">
    > <div id="divLocationLabel" runat="server">Location:</div>
    > </td>
    > <td class="clstd" style="width: 700px">
    > <div id="divLocation" runat="server">
    > <ctrllocation:location ID="LocationControlCase"
    > runat="server"
    > SelectedLocation="All">
    > </ctrllocation:location>
    > </div>
    > </td>
    > </tr></table>
    > </ContentTemplate>
    > <Triggers>
    > <asp:AsyncPostBackTrigger ControlID="ddlCaseType"
    > EventName="SelectedIndexChanged" />
    > <asp:AsyncPostBackTrigger ControlID="ddlCategory"
    > EventName="SelectedIndexChanged" />
    > </Triggers>
    > </asp:UpdatePanel>
    >
    > <asp:UpdatePanel runat="server" ID="updPnlUDEFs" UpdateMode="always">
    > <ContentTemplate>
    > <ctrlUserDefinedFields:UserDefinedFields
    > ID="ucCaseSubmissionFields" runat="server" />
    > </ContentTemplate>
    > </asp:UpdatePanel>
    >
    > Tom
     
    Harry Keck, Feb 8, 2008
    #2
    1. Advertising

  3. TomK

    TomK Guest

    I see. So is the entired rendered page sent back and only the portions
    belonging to update panels used? Or are only the parts from update panels
    sent back to the client?

    I also notice that while in a partial postback if you put a break point on
    the server the client page is unresponsive until a response is received. Is
    this normal? Since this does not seem to be "asynchronous" behaviour to me.

    "Harry Keck" wrote:

    > When you say the whole page is posting back, do you mean that it is doing the
    > "flicker" kind of postback where the entire page is re-rendered? If so, then
    > yes, you do have a problem, but I can not tell anything wrong with the code
    > you supplied.
    >
    > If, however, you simply mean that all of your server side code is running
    > everytime an updatepanel updates, then that is correct behavior. When and
    > AJAX page posts back, all of the server side code runs just as if partial
    > rendering were not enabled. The only difference is that the client will only
    > re-paint the portions marked for update.
    >
    > "TomK" wrote:
    >
    > > I have a ASP.NET 2.0 web application that was written using traditional
    > > postbacks.
    > > I am in the process of Ajaxifying some pages.
    > >
    > > PROBLEM: Update panel is always causing postbacks
    > >
    > > I have 1 test page that does partial postbacks no problem. The second page
    > > is a legacy page that I have wrapped some controls in UpdatePanels and
    > > followed a similar model as the working test page. Whenever the UpdatePanel
    > > trigger is fired I keep getting full postbacks even though I have
    > > EnablePartialRendering=true.
    > >
    > > I know it has to be something at the page level since the test page works
    > > fine.
    > >
    > > Here are some sample snippets:
    > >
    > > <asp:ScriptManager runat="server" ID="ctlScriptManager"
    > > EnablePartialRendering="true" >
    > > </asp:ScriptManager>
    > > <script type="text/javascript" language="javascript">
    > > try
    > > {
    > > var prm = Sys.WebForms.PageRequestManager.getInstance();
    > > prm.add_initializeRequest(InitializeRequest);
    > > prm.add_beginRequest(doNothing);
    > > prm.add_pageLoading(doNothing);
    > > prm.add_pageLoaded(doNothing);
    > > prm.add_endRequest(EndRequest);
    > > }catch(e)
    > > {
    > > //alert("There was an error setting up ScriptManager");
    > > }
    > >
    > > function InitializeRequest(sender, args)
    > > {
    > >
    > > alert('InitializeRequest');
    > > debugger
    > > if (prm.get_isInAsyncPostBack())
    > > {
    > > alert('cancelled double request');
    > > args.set_cancel(true);
    > > }else
    > > {
    > > if (!OnSubmitValidation())
    > > {
    > > alert('handled validation error');
    > > args.set_cancel(true);
    > > prm._originalDoPostBack(args._postBackElement.id,'');
    > > }
    > > }
    > > }
    > >
    > > function doNothing(sender, args)
    > > {
    > > }
    > >
    > > function EndRequest(sender, args)
    > > {
    > > DisableOnSubmitValidation();
    > >
    > > // TODO: handle timeout errors, and revert to fullpage postback
    > > if (args.get_error() && args.get_response().get_timedOut())
    > > {
    > > prm._originalDoPostBack(args._postBackElement.id,'');
    > > //alert('handled time out');
    > > args.set_errorHandled(true);
    > > }
    > > }
    > > </script>
    > >
    > > THIS IS THE TRIGGER CONTROL
    > > <asp:DropDownList ID="ddlCategory" alt="Category" runat="server"
    > > Width="100%" CssClass="clsDropDown" AutoPostBack="true">
    > >
    > > </asp:DropDownList>
    > >
    > > <asp:UpdatePanel runat="server"
    > > ID="updPnlCaseType" UpdateMode="Conditional">
    > > <ContentTemplate>
    > > <asp:DropDownList ID="ddlCaseType"
    > > alt="Case Type" runat="server"
    > > Width="100%" CssClass="clsDropDown"
    > > AutoPostBack="True">
    > > </asp:DropDownList>
    > > </ContentTemplate>
    > > <Triggers>
    > > <asp:AsyncPostBackTrigger ControlID="ddlCategory"
    > > EventName="SelectedIndexChanged" />
    > > </Triggers>
    > > </asp:UpdatePanel>
    > >
    > > <asp:UpdatePanel runat="server" ID="updPnlLocation" UpdateMode="Conditional">
    > > <ContentTemplate>
    > > <table><tr>
    > > <td class="clstd" style="width: 10%; vertical-align: top;">
    > > <div id="divLocationLabel" runat="server">Location:</div>
    > > </td>
    > > <td class="clstd" style="width: 700px">
    > > <div id="divLocation" runat="server">
    > > <ctrllocation:location ID="LocationControlCase"
    > > runat="server"
    > > SelectedLocation="All">
    > > </ctrllocation:location>
    > > </div>
    > > </td>
    > > </tr></table>
    > > </ContentTemplate>
    > > <Triggers>
    > > <asp:AsyncPostBackTrigger ControlID="ddlCaseType"
    > > EventName="SelectedIndexChanged" />
    > > <asp:AsyncPostBackTrigger ControlID="ddlCategory"
    > > EventName="SelectedIndexChanged" />
    > > </Triggers>
    > > </asp:UpdatePanel>
    > >
    > > <asp:UpdatePanel runat="server" ID="updPnlUDEFs" UpdateMode="always">
    > > <ContentTemplate>
    > > <ctrlUserDefinedFields:UserDefinedFields
    > > ID="ucCaseSubmissionFields" runat="server" />
    > > </ContentTemplate>
    > > </asp:UpdatePanel>
    > >
    > > Tom
     
    TomK, Feb 8, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    484
    Rob Meade
    Aug 8, 2007
  2. Jeremy
    Replies:
    1
    Views:
    1,144
    Nathan Sokalski
    Oct 10, 2007
  3. TomK
    Replies:
    1
    Views:
    1,969
    Manish
    Feb 6, 2008
  4. Nathan Sokalski
    Replies:
    1
    Views:
    594
    miher
    Jun 15, 2009
  5. Monty
    Replies:
    7
    Views:
    665
    baradi hakim
    Jan 29, 2007
Loading...

Share This Page