Wednesday, March 28, 2012

Change full postback action from inner update panel...

Hi,

Is there a way to alter full postback to partial postback caused by outer update panels from usercontrol?Huh?Confused...I tried to add button control as an AsyncPostBackTrigger. No effect to change from a full page postback to partial one. No change whether I set properties like ChildrenAsTriggers to false/true and UpdateMode to Always/Conditional inner update panel, when a button or any control causes a postback action is pressed, it causes a full postback.


Parent:

<asp:UpdatePanel ID="upanelPage" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<asp:UpdatePanel ID="upanelMainContent" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<!-- Main Content --> <<-- my user control or other are displayed
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>

User Control loaded to Parent...

<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<ajaxToolkit:TabContainer ...>
<ajaxToolkit:TabPanel ...>
<asp:MultiView...>
<asp:View...>
...
<asp:LinkButton...></asp:LinkButton>
<asp:Button...></asp:Button>
<asp:UpdatePanel ...>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=.../>
</Triggers>
<ContentTemplate>
...
<asp:GridView...>
</asp:GridView>
...
</ContentTemplate>
</asp:UpdatePanel>
...
</asp:View...>
<asp:View...>
...controls...
</asp:View>
</asp:MultiView>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ...>

</ajaxToolkit:TabPanel>
...
</ajaxToolkit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>

UpdatePanel causes a Full Post Back no matter what properties you set on it.

If you are looking for better performing alternatives, look out for ScriptCallbacks or JSON Based Calls and this would require "some" work compared to ourmagic updatepanel!


Huh??ConfusedScriptCallbacks?ConfusedJSon Based Calls?Hmm...Does not know what are they or how to start with them? ..thanks for the reply..


Huh??ConfusedScriptCallbacks?ConfusedJSon Based Calls?Hmm...Does not know what are they or how to start with them? I was trying to control the postback action of outer update panel from the inside user control..thanks for the reply..


Hi,den2005

I found that the following code worked.

The Page:

<%@. Page Language="C#" %>

<%@. Register src="http://pics.10026.com/?src=WebUserControl2.ascx" TagName="WebUserControl2" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Tutorial</title>
<style type="text/css">
#UpdatePanel2 {
position: relative;
margin: 2% 5% 2% 5%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ChildrenAsTriggers="False" ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<fieldset>
<legend>Parent UpdatePanel</legend>Last refresh
<%=DateTime.Now.ToString() %>
<br />
<asp:Button ID="Button1" runat="server" Text="Refresh Outer Panel" />
<uc1:WebUserControl2 ID="WebUserControl2_1" runat="server" />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

The UserControl:

<%@. Control Language="C#" ClassName="WebUserControl2" %>
<asp:UpdatePanel ChildrenAsTriggers="False" ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<legend>Nested UpdatePanel</legend>Last refresh
<%=DateTime.Now.ToString() %>
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Calendar1" />
</Triggers>
</asp:UpdatePanel>

Hope this help.

Best regards.

Jin-Yu Yin

No comments:

Post a Comment