Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > UpdatePanel is doing full postback when it should not

Reply
Thread Tools

UpdatePanel is doing full postback when it should not

 
 
TomK
Guest
Posts: n/a
 
      02-05-2008
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
<aspropDownList ID="ddlCategory" alt="Category" runat="server"
Width="100%" CssClass="clsDropDown" AutoPostBack="true">

</aspropDownList>

<asp:UpdatePanel runat="server"
ID="updPnlCaseType" UpdateMode="Conditional">
<ContentTemplate>
<aspropDownList ID="ddlCaseType"
alt="Case Type" runat="server"
Width="100%" CssClass="clsDropDown"
AutoPostBack="True">
</aspropDownList>
</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
 
Reply With Quote
 
 
 
 
Manish
Guest
Posts: n/a
 
      02-06-2008
Hi Tom,

I am not able to replicate the issue. I tried the following code to write
the selected value of the Dropdownlist on the selectedChangedevent on
callback.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<aspropDownList ID="DropDownList1" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="ProductID" DataValueField="ProductID"
OnSelectedIndexChanged="DropDownList1_SelectedInde xChanged"
Style="z-index: 100; left: 162px; position: absolute; top: 241px">
</aspropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName] FROM
[Alphabetical list of products]">
</asp:SqlDataSource>
</form>
</body>
</html>

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Debug.WriteLine(this.DropDownList1.SelectedItem.To String());
}

Regards,
Manish
www.ComponentOne.com




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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triggering an UpdatePanel with a trigger located outside of the UpdatePanel Nathan Sokalski ASP .Net 1 06-15-2009 06:23 PM
UpdatePanel is doing full postback when it should not TomK ASP .Net Web Controls 2 02-08-2008 09:51 PM
exclude control in updatepanel from doing async postback Jeremy ASP .Net 1 10-10-2007 09:42 PM
refresh an updatePanel in an other updatePanel fran_j_diaz@yahoo.fr ASP .Net 3 08-08-2007 06:30 AM
AJAX n00b - custom server control in an UpdatePanel causes full postback Monty ASP .Net Web Controls 7 01-29-2007 01:29 PM



Advertisments