代码之家  ›  专栏  ›  技术社区  ›  RacerNerd

UpdatePanel计时器触发器不工作

  •  2
  • RacerNerd  · 技术社区  · 11 年前

    我正在尝试获取计时器以触发对UpdatePanel的更新,但无法触发事件。我正在处理的例子非常基本,我不确定我需要检查什么才能弄清真相。

    我有一个很长的运行过程(大约一个小时),用于评估数据库内容并找出有问题的行。 我想创建一个页面,允许用户执行流程,并在流程前进时查看进度。当发现问题行时,我想将该信息打印到页面上,这样用户就可以立即看到它,而不是等待任务完成。

    要做到这一点,我想我应该使用一个每秒都有一个Timer触发器的UpdatePanel。此页面只能由专用服务器上的管理员访问,因此流量不是问题。我不确定这是否是最好的方法,所以如果有其他方法可以处理这项任务,我应该考虑,请随时提出建议。

    为了测试这个概念,我从 UpdatePanel Timer causes all panels to update 。我按照建议修改了一些内容,并生成了下面显示的代码。

    当我执行代码时,我可以选择一个下拉选项并获取第二个UpdatePanel进行更新,但Timer永远不会执行。我在Timer1_Tick函数上放置了一个断点,但它没有被击中。

    我还观察到,当我从下拉菜单中选择一个项目时,Page_Load会被点击。我没想到这个功能会在更新时被点击,是吗?

    ASPX文件:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MissingTitles2.aspx.cs" Inherits="TestCode_AJAX_MissingTitles2" %>
    
    <!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>
    </head>
    <body>
     <form id="form1" runat="server">
    <div>
        <asp:Label runat="server" ID="NoChangeLabel"></asp:Label>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="not updated yet"></asp:Label>
                <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick"></asp:Timer>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
        <br />
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="Label2" runat="server" Text="also not updated yet"></asp:Label>
        <br />
        <br />
        <asp:DropDownList  OnSelectedIndexChanged="dropDown_indexChange" ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem>This</asp:ListItem>
            <asp:ListItem>That</asp:ListItem>
            <asp:ListItem>The Other</asp:ListItem>
        </asp:DropDownList>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="DropDownList1"  EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    </form>
    </body>
    </html>
    

    以下是ASPX.CS文件:

    using System;
    
    public partial class TestCode_AJAX_MissingTitles2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            NoChangeLabel.Text = "Current time: " + DateTime.Now.ToLongTimeString();
        }
    
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Label1.Text = "UpdatePanel1 refreshed at: " +
          DateTime.Now.ToLongTimeString();
    
        }
    
        protected void dropDown_indexChange(object sender, EventArgs e)
        {
            Label2.Text = "UpdatePanel2 refreshed at: " +
              DateTime.Now.ToLongTimeString();
        }
    }
    

    我正在将Visual Studio 2010与ASP.NET 4.0一起使用。
    我已经用localhost和127.0.0.1作为域进行了测试。

    Web.Config摘录:

    <system.web>
        <webParts>
          <personalization defaultProvider="EktronPersonalizationProvider">
            <providers>
              <add connectionStringName="Ektron.DbConnection" name="EktronPersonalizationProvider" type="Ektron.Cms.EktronPersonalizationProvider"/>
            </providers>
            <authorization>
              <allow users="*" verbs="enterSharedScope"/>
              <allow users="*" verbs="modifyState"/>
            </authorization>
          </personalization>
        </webParts>
        <membership defaultProvider="EktronMembershipProvider">
          <providers>
            <remove name="AspNetSqlProvider"/>
            <add name="EktronMembershipProvider" type="Ektron.Cms.EktronMembershipProvider" connectionStringName="Ektron.DbConnection"/>
          </providers>
        </membership>
        <compilation debug="true" targetFramework="4.0">
          <buildProviders>
            <add extension=".htm" type="System.Web.Compilation.PageBuildProvider"/>
            <add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
          </buildProviders>
          <codeSubDirectories>
            <add directoryName="CSCode"/>
            <add directoryName="VBCode"/>
          </codeSubDirectories>
          <assemblies>
            <add assembly="System.DirectoryServices,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Security,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Management,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Configuration.Install,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Windows.Forms,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.ServiceProcess,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Messaging,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Runtime.Remoting,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B77A5C561934E089"/>
            <add assembly="Microsoft.VisualBasic.Compatibility,Version=10.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Design,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Web.Extensions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="Microsoft.VisualBasic,Version=10.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Data.DataSetExtensions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.ComponentModel.Composition,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B77A5C561934E089"/>
          </assemblies>
        </compilation>
        <caching>
          <outputCacheSettings>
            <outputCacheProfiles>
              <add name="PageLevelCaching" duration="120" varyByCustom="IsLoggedIn" varyByParam="*" location="Server"/>
            </outputCacheProfiles>
          </outputCacheSettings>
        </caching>
        <pages clientIDMode="AutoID" controlRenderingCompatibilityVersion="3.5" validateRequest="false">
          <controls>
            <add tagPrefix="ektronUI" namespace="Ektron.Cms.Framework.UI.Controls.EktronUI" assembly="Ektron.Cms.Framework.UI.Controls.EktronUI, Culture=neutral, PublicKeyToken=559a2c4fa21e63be"/>
            <add tagPrefix="ektron" namespace="Ektron.Cms.Framework.UI.Controls" assembly="Ektron.Cms.Framework.UI.Controls, Culture=neutral, PublicKeyToken=559a2c4fa21e63be"/>
            <add tagPrefix="ektron" namespace="Ektron.Cms.Framework.UI.Controls.Views" assembly="Ektron.Cms.Framework.UI.Controls, Culture=neutral, PublicKeyToken=559a2c4fa21e63be"/>
          </controls>
          <namespaces>
            <clear/>
            <add namespace="System"/>
            <add namespace="System.Collections"/>
            <add namespace="System.Collections.Generic"/>
            <add namespace="System.Collections.Specialized"/>
            <add namespace="System.Configuration"/>
            <add namespace="System.Text"/>
            <add namespace="System.Text.RegularExpressions"/>
            <add namespace="System.Linq"/>
            <add namespace="System.Xml.Linq"/>
            <add namespace="System.Web"/>
            <add namespace="System.Web.Caching"/>
            <add namespace="System.Web.SessionState"/>
            <add namespace="System.Web.Security"/>
            <add namespace="System.Web.Profile"/>
            <add namespace="System.Web.UI"/>
            <add namespace="System.Web.UI.WebControls"/>
            <add namespace="System.Web.UI.WebControls.WebParts"/>
            <add namespace="System.Web.UI.HtmlControls"/>
          </namespaces>
        </pages>
        <customErrors mode="Off"/>
        <authentication mode="Forms">
          <forms cookieless="UseCookies"/>
        </authentication>
        <identity impersonate="false" userName="" password=""/>
        <authorization>
          <allow users="*"/>
        </authorization>
        <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
        <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>
        <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
        <webServices>
          <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
          </protocols>
        </webServices>
        <httpRuntime maxRequestLength="2097151" requestLengthDiskThreshold="2097151" requestValidationMode="2.0"/>
      </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <clear/>
          <add name="WebServiceHandlerFactory-Integrated" path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode"/>
          <add name="rules-Integrated" path="*.rules" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode"/>
          <add name="rules-ISAPI-2.0" path="*.rules" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32"/>
          <add name="rules-64-ISAPI-2.0" path="*.rules" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness64"/>
          <add name="xoml-Integrated" path="*.xoml" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode"/>
          <add name="xoml-ISAPI-2.0" path="*.xoml" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32"/>
          <add name="xoml-64-ISAPI-2.0" path="*.xoml" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness64"/>
          <add name="ISAPI-dll" path="*.dll" verb="*" modules="IsapiModule" resourceType="File" requireAccess="Execute" allowPathInfo="true"/>
          <add name="TraceHandler-Integrated" path="trace.axd" verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TraceHandler" preCondition="integratedMode"/>
          <add name="WebAdminHandler-Integrated" path="WebAdmin.axd" verb="GET,DEBUG" type="System.Web.Handlers.WebAdminHandler" preCondition="integratedMode"/>
          <add name="AssemblyResourceLoader-Integrated" path="WebResource.axd" verb="GET,DEBUG" type="System.Web.Handlers.AssemblyResourceLoader" preCondition="integratedMode"/>
          <add name="WorkareaHandler" path="*/WorkArea/ContentDesigner/configurations/*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode"/>
          <add name="PageHandlerFactory-Integrated" path="*.aspx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode"/>
          <add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode"/>
          <add name="HttpRemotingHandlerFactory-rem-Integrated" path="*.rem" verb="GET,HEAD,POST,DEBUG" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode"/>
          <add name="HttpRemotingHandlerFactory-soap-Integrated" path="*.soap" verb="GET,HEAD,POST,DEBUG" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode"/>
          <add name="AboMapperCustom-4879914" path="*.htw" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\system32\webhits.dll" requireAccess="Script" responseBufferLimit="0"/>
          <add name="AboMapperCustom-4879915" path="*.ida" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\system32\idq.dll" resourceType="File" requireAccess="Script" responseBufferLimit="0"/>
          <add name="AboMapperCustom-4879916" path="*.idq" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\system32\idq.dll" resourceType="File" requireAccess="Script" responseBufferLimit="0"/>
          <add name="EktronWorkflowImage" path="*/wfactivities.png" verb="*" type="Ektron.Workflow.Image.Handler.WFImageHandler,Ektron.Workflow.Image"/>
          <add name="AXD-ISAPI-2.0-64" path="*.axd" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
          <add name="PageHandlerFactory-ISAPI-2.0-64" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
          <add name="SimpleHandlerFactory-ISAPI-2.0-64" path="*.ashx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
          <add name="WebServiceHandlerFactory-ISAPI-2.0-64" path="*.asmx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
          <add name="HttpRemotingHandlerFactory-rem-ISAPI-2.0-64" path="*.rem" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
          <add name="HttpRemotingHandlerFactory-soap-ISAPI-2.0-64" path="*.soap" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
          <add name="AXD-ISAPI-2.0" path="*.axd" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
          <add name="PageHandlerFactory-ISAPI-2.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
          <add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
          <add name="WebServiceHandlerFactory-ISAPI-2.0" path="*.asmx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
          <add name="HttpRemotingHandlerFactory-rem-ISAPI-2.0" path="*.rem" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
          <add name="HttpRemotingHandlerFactory-soap-ISAPI-2.0" path="*.soap" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
          <add name="TRACEVerbHandler" path="*" verb="TRACE" modules="ProtocolSupportModule" requireAccess="None"/>
          <add name="ek*" path="*" verb="GET,HEAD,POST" type="Ektron.ASM.EkHttpDavHandler.EkDavHttpHandlerFactory" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition=""/>
          <add name="ekdav" path="*" verb="OPTIONS,PROPFIND,PUT,LOCK,UNLOCK,MOVE,COPY,GETLIB,PROPPATCH,MKCOL,DELETE,(GETSOURCE),(HEADSOURCE),(POSTSOURCE)" type="Ektron.ASM.EkHttpDavHandler.EkDavHttpHandlerFactory" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition=""/>
          <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read"/>
    
    
        </handlers>
        <modules>
          <add name="MyDigestAuthenticationModule" type="Ektron.ASM.EkHttpDavHandler.Security.DigestAuthenticationModule,Ektron.ASM.EkHttpDavHandler"/>
          <add name="EkUrlAliasModule" type="Ektron.Cms.Settings.UrlAliasing.URLAliasingModule" preCondition="integratedMode"/>
          <add name="EkUrlRedirectModule" type="Ektron.Cms.Settings.UrlAliasing.URLRedirectModule" preCondition="integratedMode"/>
          <add name="EkMobileDeviceModule" type="Ektron.Cms.Settings.UrlAliasing.MobileDeviceModule" preCondition="integratedMode"/>
          <add name="EkAssetServerModule" type="EktronAssetServerModule" preCondition="integratedMode"/>
          <add name="EkHelpModule" type="HelpModule" preCondition="integratedMode"/>
        </modules>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483648"/>
          </requestFiltering>
        </security>
        <caching>
          <profiles>
            <add extension=".xslt" policy="DontCache" kernelCachePolicy="DontCache"/>
            <add extension=".xsl" policy="DontCache" kernelCachePolicy="DontCache"/>
            <add extension=".aspx.cs" policy="DontCache" kernelCachePolicy="DontCache"/>
          </profiles>
        </caching>
      </system.webServer>
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Community pid    7 年前

    我终于弄清了这件事的真相。最后,这归结为web.config文件中的设置。

    令人困惑的一个原因是,我创建的测试项目在web.config文件中不需要这些。非测试项目要复杂得多,并且必须具有导致需要这些额外行的设置。我很好奇导致需要这样做的确切设置,所以如果有人知道,这将有助于增加讨论。

    在web.config文件中添加以下条目纠正了这种情况,并允许UpdatePanel运行:

        <system.webServer>
        <handlers>
          <clear />
          <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <!-- Make sure wildcard rules are below the ScriptResource tag -->
        </handlers>
        <modules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <!-- Other modules are added here -->
        </modules>
      </system.webServer>
    

    以下是一个问题的链接,该问题在排除故障时很有帮助,以防有人遇到同样的问题: Sys is undefined

    感谢所有发表评论的人,他们非常有助于我继续前进,并确保我对正确的位置进行了故障排除。