944,149 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 3703
  • ASP.NET RSS
Oct 26th, 2009
0

Partial Page Postback not working

Expand Post »
Hi, having a problem implementing partial page postbacks using a scriptmanager and an update panel. Here is a test page using a web form to call a user control. I am hitting the else statement in the code behind that confirms I do not have a functioning partial post back.

Web Form [TestPartialPage.aspx]:

asp.net Syntax (Toggle Plain Text)
  1. <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Templates/main.Master" CodeBehind="TestPartialPage.aspx.cs" Inherits="BayCare.PreReg.Web.Pages.TestPartialPage" %>
  2. <%@ Register src="../UserControls/TestPartPagePost.ascx" tagname="TestPartPagePost" tagprefix="uc2" %>
  3. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  4. </asp:Content>
  5. <asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server">
  6. <uc2:TestPartPagePost runat="server" />
  7. </asp:Content>


User Control [TestPartPagePost.ascx]:

asp.net Syntax (Toggle Plain Text)
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestPartPagePost.ascx.cs" Inherits="BayCare.PreReg.Web.UserControls.TestPartPagePost" %>
  2. <%@ Register Assembly="AjaxControlToolkit, Version=3.0.11119.25533, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
  3. Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
  4. <asp:ScriptManager ID="_preRegScriptManager" EnablePartialRendering="true" AsyncPostBackTimeout="200" runat="server" LoadScriptsBeforeUI="false" ScriptMode="Debug" />
  5. <div>
  6. <br /><br />
  7. <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  8. <br /><br />&nbsp;&nbsp;
  9. <asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true">
  10. <asp:ListItem Text="1" Value="1" />
  11. <asp:ListItem Text="2" Value="2" />
  12. <asp:ListItem Text="3" Value="3" />
  13. <asp:ListItem Text="4" Value="4" />
  14. <asp:ListItem Text="5" Value="5" />
  15. <asp:ListItem Text="6" Value="6" />
  16. <asp:ListItem Text="7" Value="7" />
  17. <asp:ListItem Text="8" Value="8" />
  18. </asp:DropDownList>
  19. <asp:UpdatePanel ID="updatePanel" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
  20. <ContentTemplate>
  21. <asp:Repeater ID="rptr" runat="server">
  22. <ItemTemplate>
  23. <div><%# Container.DataItem %></div>
  24. </ItemTemplate>
  25. </asp:Repeater>
  26. </ContentTemplate>
  27. <Triggers>
  28. <asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
  29. </Triggers>
  30. </asp:UpdatePanel>
  31. </div>


Code Behind [TestPartialPage.aspx.cs]

asp.net Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Collections;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Web.Security;
  11. using System.Web.UI.HtmlControls;
  12. using System.Web.UI.WebControls.WebParts;
  13. using System.Xml.Linq;
  14.  
  15. namespace BayCare.PreReg.Web.UserControls
  16. {
  17. public partial class TestPartPagePost : System.Web.UI.UserControl
  18. {
  19. List<string> data = new List<string>();
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22. if (_preRegScriptManager.IsInAsyncPostBack)
  23. {
  24. Label1.Text = "AJAX postback at : " + DateTime.Now.ToString();
  25. }
  26. else
  27. {
  28. Label1.Text = "Not AJAX postback";
  29. }
  30. if (!IsPostBack)
  31. {
  32. for (int i = 0; i < 1; i++)
  33. {
  34. data.Add(string.Format("Item {0}", i));
  35. }
  36. this.rptr.DataSource = data;
  37. this.rptr.DataBind();
  38. this.ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
  39. }
  40. }
  41. protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
  42. {
  43. // get the number selected
  44. int num = int.Parse(this.ddl.SelectedValue);
  45. for (int i = 0; i < num; i++)
  46. {
  47. data.Add(string.Format("Item {0}", i));
  48. }
  49. this.rptr.DataSource = data;
  50. this.rptr.DataBind();
  51. }
  52. }
  53. }
Last edited by peter_budo; Oct 27th, 2009 at 10:48 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bylandsend is offline Offline
4 posts
since Jun 2009
Oct 26th, 2009
0
Re: Partial Page Postback not working
Actually your code is doing a Partial PostBack...But Your Label is outside of UpdatePanel....so upon partial postback only Contents inside of UpdatePanel will be update and not the Label Text which is outside or UP.
Move your Label inside the UP and you will see the appropriate text.
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
guru_sarkar is offline Offline
68 posts
since Jul 2008
Oct 27th, 2009
0

Update still not working

Hello Thanks for the response I placed the label into the <ContentTemplate> section as suggested but still getting the same result, basically the 'IsInAsyncPostBack' in Page_Load is still reporting 'Not AJAX postback'.

Here is my [web.config] to add to the files previously sent
ASP.NET Syntax (Toggle Plain Text)
  1. <?xml version="1.0"?>
  2. <configuration>
  3. <configSections>
  4. <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  5. <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  6. <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  7. <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  8. <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
  9. <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  10. <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  11. <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  12. </sectionGroup>
  13. </sectionGroup>
  14. </sectionGroup>
  15. </configSections>
  16.  
  17. <appSettings>
  18. <add key="LoggingPolicy" value="Logging Policy"/>
  19. </appSettings>
  20.  
  21. <connectionStrings />
  22.  
  23. <system.web>
  24. <trust level="Full" />
  25. <!--
  26. Set compilation debug="true" to insert debugging
  27. symbols into the compiled page. Because this
  28. affects performance, set this value to true only
  29. during development.
  30. -->
  31. <compilation debug="true">
  32. <assemblies>
  33. <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  34. <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  35. <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  36. <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  37. <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
  38. <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  39. </assemblies>
  40. </compilation>
  41. <!--
  42. The <authentication> section enables configuration
  43. of the security authentication mode used by
  44. ASP.NET to identify an incoming user.
  45. -->
  46.  
  47. <!-- using locally -->
  48. <!--<authentication mode="Windows">-->
  49.  
  50. <authentication mode="Forms">
  51. <forms name="PREG" loginUrl="~/default.aspx" timeout="15" path="/" requireSSL="false" cookieless="UseCookies" defaultUrl="~/Pages/PreRegStep1.aspx" />
  52. </authentication>
  53.  
  54.  
  55. <!--
  56. The <customErrors> section enables configuration
  57. of what to do if/when an unhandled error occurs
  58. during the execution of a request. Specifically,
  59. it enables developers to configure html error pages
  60. to be displayed in place of a error stack trace.
  61. -->
  62. <customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
  63. <error statusCode="403" redirect="NoAccess.htm" />
  64. <error statusCode="404" redirect="FileNotFound.htm" />
  65. </customErrors>
  66.  
  67. <pages theme="BayCare" enableEventValidation="false" enableViewStateMac="false" viewStateEncryptionMode="Never">
  68. <controls>
  69. <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  70. <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  71. </controls>
  72. </pages>
  73.  
  74. <httpHandlers>
  75. <remove verb="*" path="*.asmx"/>
  76. <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  77. <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  78. <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
  79. </httpHandlers>
  80. <httpModules>
  81. <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  82. </httpModules>
  83.  
  84. </system.web>
  85. <system.codedom>
  86. <compilers>
  87. <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  88. <providerOption name="CompilerVersion" value="v3.5"/>
  89. <providerOption name="WarnAsError" value="false"/>
  90. </compiler>
  91. </compilers>
  92. </system.codedom>
  93.  
  94. <!--
  95. The system.webServer section is required for running ASP.NET AJAX under Internet
  96. Information Services 7.0. It is not necessary for previous version of IIS.
  97. -->
  98. <system.webServer>
  99. <validation validateIntegratedModeConfiguration="false"/>
  100. <modules>
  101. <remove name="ScriptModule"/>
  102. <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  103.  
  104. </modules>
  105. <handlers>
  106. <remove name="WebServiceHandlerFactory-Integrated"/>
  107. <remove name="ScriptHandlerFactory"/>
  108. <remove name="ScriptHandlerFactoryAppServices"/>
  109. <remove name="ScriptResource"/>
  110. <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  111. <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  112. <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  113.  
  114. </handlers>
  115. </system.webServer>
  116. <runtime>
  117. <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  118. <dependentAssembly>
  119. <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
  120. <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
  121. </dependentAssembly>
  122. <dependentAssembly>
  123. <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
  124. <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
  125. </dependentAssembly>
  126. </assemblyBinding>
  127. </runtime>
  128. </configuration>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bylandsend is offline Offline
4 posts
since Jun 2009
Oct 27th, 2009
0
Re: Partial Page Postback not working
Not sure ...because I took your code, moved the Label within UP and it worked.
do you mind creating a test page... and trying this sample to see if your ASP.NET ajax is working.

http://www.asp.net/AJAX/Documentatio...eMarkupCS.aspx

To add to the above example ....Place a Label outside of UP and upon Page_Load set its Text to DateTime.Now
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
guru_sarkar is offline Offline
68 posts
since Jul 2008
Oct 30th, 2009
0

Heading in right direction

Hello, Heading in right direction but where your suggested test page's content is all in one .aspx form, my original page using .aspx and .ascx page along with a master page is still not working. Here is your page with my edit for two timestamps (one inside / one outside the UP). I'm including my master page below your test script. Thanks again for the suggestions ....

ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. <%@ Page Language="C#" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. </script>
  6. <html xmlns="http://www.w3.org/1999/xhtml" >
  7. <head id="Head1" runat="server">
  8. <title>UpdatePanel Trigger Declarative Syntax</title>
  9. <style type="text/css">
  10. body {
  11. font-family: Lucida Sans Unicode;
  12. font-size: 10pt;
  13. }
  14. button {
  15. font-family: tahoma;
  16. font-size: 8pt;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <form id="form1" runat="server">
  22. <div>
  23. <asp:Label ID="Label1" runat="server" Text="label" ><%=DateTime.Now.ToString() %></asp:Label>
  24. <asp:Button ID="Button1"
  25. Text="Refresh Now"
  26. runat="server" />
  27. <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true"
  28. runat="server" />
  29. <asp:UpdatePanel ID="UpdatePanel1"
  30. UpdateMode="Conditional"
  31. runat="server">
  32. <Triggers>
  33. <asp:AsyncPostBackTrigger ControlID="Button1" />
  34. </Triggers>
  35. <ContentTemplate>
  36. <fieldset>
  37. <legend>UpdatePanel content</legend>
  38. <%=DateTime.Now.ToString() %>
  39. </fieldset>
  40. </ContentTemplate>
  41. </asp:UpdatePanel>
  42. </div>
  43. </form>
  44. </body>
  45. </html>


[Main.Master]
ASP.NET Syntax (Toggle Plain Text)
  1. <%@ Master Language="C#" AutoEventWireup="true" EnableTheming="true" CodeBehind="main.master.cs" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title></title>
  8. <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
  9. </head>
  10. <body>
  11. <form id="Form1" runat="server">
  12. <script language="javascript" type="text/javascript" src="../ClientScript/UIControllers.js" id="JavaScriptUiControllerScripts" />
  13. <%--<asp:ScriptManager ID="_preRegScriptManager" EnablePartialRendering="true" AsyncPostBackTimeout="200" runat="server" LoadScriptsBeforeUI="false" ScriptMode="Debug" />--%>
  14. <div class="clear"></div>
  15.  
  16. <div class="mainContent">
  17. <div class="secColWrap" id="secMain">
  18. <asp:ContentPlaceHolder ID="PlaceHolderMain" runat="server" />
  19. </div>
  20. </div>
  21. </form>
  22. </body>
  23. </html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bylandsend is offline Offline
4 posts
since Jun 2009
Nov 3rd, 2009
0

Resolution to Partial Page Postback not working

Hello, Have found that in my master page the reference to the JavaScript resource file 'UIControllers.js' needs to be registered to the scriptmanager. Here is a code snip that registers the JavaScript resource file to the scriptmanager. Partial Page postbacks then began working as expected. Hope this thread helps someone down the line.

[code snippet inside master page]

<asp:ScriptManager ID="_preRegScriptManager" EnablePartialRendering="true" AsyncPostBackTimeout="200" runat="server" LoadScriptsBeforeUI="false" ScriptMode="Debug" >
<Scripts>
<asp:ScriptReference Path="../ClientScript/UIControllers.js" />
</Scripts>
</asp:ScriptManager>

[/code snippet]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bylandsend is offline Offline
4 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Query MS Access data based on week selection on Calendar control in Visual Studio
Next Thread in ASP.NET Forum Timeline: Contact form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC