1.11M Members

Partial Page Postback not working

 
0
 

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]:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Templates/main.Master" CodeBehind="TestPartialPage.aspx.cs" Inherits="BayCare.PreReg.Web.Pages.TestPartialPage" %>
<%@ Register src="../UserControls/TestPartPagePost.ascx" tagname="TestPartPagePost" tagprefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <uc2:TestPartPagePost runat="server" />
</asp:Content>

User Control [TestPartPagePost.ascx]:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestPartPagePost.ascx.cs" Inherits="BayCare.PreReg.Web.UserControls.TestPartPagePost" %>
<%@ Register Assembly="AjaxControlToolkit, Version=3.0.11119.25533, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
	Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
	<asp:ScriptManager ID="_preRegScriptManager" EnablePartialRendering="true"  AsyncPostBackTimeout="200" runat="server" LoadScriptsBeforeUI="false" ScriptMode="Debug" />
    <div>
    <br /><br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <br /><br />&nbsp;&nbsp;        
        <asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true">
			<asp:ListItem Text="1" Value="1" />
			<asp:ListItem Text="2" Value="2" />
			<asp:ListItem Text="3" Value="3" />
			<asp:ListItem Text="4" Value="4" />
			<asp:ListItem Text="5" Value="5" />
			<asp:ListItem Text="6" Value="6" />
			<asp:ListItem Text="7" Value="7" />
			<asp:ListItem Text="8" Value="8" />
		</asp:DropDownList>
		<asp:UpdatePanel ID="updatePanel" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
			<ContentTemplate>
				<asp:Repeater ID="rptr" runat="server">
					<ItemTemplate>
						<div><%# Container.DataItem %></div>
					</ItemTemplate>
				</asp:Repeater>
			</ContentTemplate>
			<Triggers>
				<asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
			</Triggers>
		</asp:UpdatePanel>
    </div>

Code Behind [TestPartialPage.aspx.cs]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace BayCare.PreReg.Web.UserControls
{
    public partial class TestPartPagePost : System.Web.UI.UserControl
    {
        List<string> data = new List<string>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_preRegScriptManager.IsInAsyncPostBack)
            {
                Label1.Text = "AJAX postback at : " + DateTime.Now.ToString();
            }
            else
            {
                Label1.Text = "Not AJAX postback";
            }
            if (!IsPostBack)
            {
                for (int i = 0; i < 1; i++)
                {
                    data.Add(string.Format("Item {0}", i));
                }
                this.rptr.DataSource = data;
                this.rptr.DataBind();
                this.ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
            }
        }
        protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get the number selected
            int num = int.Parse(this.ddl.SelectedValue);
            for (int i = 0; i < num; i++)
            {
                data.Add(string.Format("Item {0}", i));
            }
            this.rptr.DataSource = data;
            this.rptr.DataBind();
        }
    }
}
 
0
 

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.

 
0
 

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

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>

  <appSettings>
    <add key="LoggingPolicy" value="Logging Policy"/>
  </appSettings>

  <connectionStrings />

  <system.web>
    <trust level="Full" />
    <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
    <compilation debug="true">
      <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->

    <!-- using locally -->
    <!--<authentication mode="Windows">-->

    <authentication mode="Forms">
      <forms name="PREG" loginUrl="~/default.aspx" timeout="15" path="/" requireSSL="false" cookieless="UseCookies" defaultUrl="~/Pages/PreRegStep1.aspx" />
    </authentication>


    <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.
 -->
    <customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
      <error statusCode="403" redirect="NoAccess.htm" />
      <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>

    <pages theme="BayCare" enableEventValidation="false" enableViewStateMac="false" viewStateEncryptionMode="Never">
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
    </pages>

    <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <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"/>
      <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"/>
    </httpHandlers>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>

  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>

  <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ScriptModule"/>
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    </modules>
    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <remove name="ScriptHandlerFactory"/>
      <remove name="ScriptHandlerFactoryAppServices"/>
      <remove name="ScriptResource"/>
      <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"/>
      <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"/>
      <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"/>

    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
 
0
 

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/Documentation/Live/ViewSample.aspx?sref=UpdatePanelWalkthrough2%23TriggersDeclarativeMarkupCS.aspx

To add to the above example ....Place a Label outside of UP and upon Page_Load set its Text to DateTime.Now

 
0
 

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 ....

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>UpdatePanel Trigger Declarative Syntax</title>
    <style type="text/css">
    body {
        font-family: Lucida Sans Unicode;
        font-size: 10pt;
    }
    button {
        font-family: tahoma;
        font-size: 8pt;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" runat="server" Text="label" ><%=DateTime.Now.ToString() %></asp:Label>
    <asp:Button ID="Button1" 
                Text="Refresh Now"
                runat="server" />
    <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" 
                       runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" 
                     UpdateMode="Conditional"
                     runat="server">
                     <Triggers>
                       <asp:AsyncPostBackTrigger ControlID="Button1" />
                     </Triggers>
                     <ContentTemplate>
                     <fieldset>
                     <legend>UpdatePanel content</legend>
                     <%=DateTime.Now.ToString() %>
                     </fieldset>
                     </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

[Main.Master]

<%@ Master Language="C#" AutoEventWireup="true" EnableTheming="true" CodeBehind="main.master.cs" %>

<!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 runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>  
</head>
<body>
   <form id="Form1" runat="server">
       <script language="javascript" type="text/javascript" src="../ClientScript/UIControllers.js" id="JavaScriptUiControllerScripts" />
	<%--<asp:ScriptManager ID="_preRegScriptManager" EnablePartialRendering="true"  AsyncPostBackTimeout="200" runat="server" LoadScriptsBeforeUI="false" ScriptMode="Debug" />--%>
	<div class="clear"></div>

	<div class="mainContent">
		<div class="secColWrap" id="secMain">
			<asp:ContentPlaceHolder ID="PlaceHolderMain" runat="server" />
		</div>
	</div>
	</form>
</body>
</html>
 
0
 

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.

<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][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]

Question Answered as of 4 Years Ago by guru_sarkar
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article