T
TomK
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
ropDownList ID="ddlCategory" alt="Category" runat="server"
Width="100%" CssClass="clsDropDown" AutoPostBack="true">
</asp
ropDownList>
<asp:UpdatePanel runat="server"
ID="updPnlCaseType" UpdateMode="Conditional">
<ContentTemplate>
<asp
ropDownList ID="ddlCaseType"
alt="Case Type" runat="server"
Width="100%" CssClass="clsDropDown"
AutoPostBack="True">
</asp
ropDownList>
</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
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
Width="100%" CssClass="clsDropDown" AutoPostBack="true">
</asp
<asp:UpdatePanel runat="server"
ID="updPnlCaseType" UpdateMode="Conditional">
<ContentTemplate>
<asp
alt="Case Type" runat="server"
Width="100%" CssClass="clsDropDown"
AutoPostBack="True">
</asp
</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