2

我正在尝试让计时器触发对 UpdatePanel 的更新,但无法触发事件。我正在使用的示例非常基本,我不确定需要检查什么才能深入了解。

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

为此,我想我会使用每秒有一个 Timer 触发器的 UpdatePanel。此页面只能由私人服务器上的管理员访问,因此流量不是问题。我不确定这是不是最好的方法,所以如果我应该考虑另一种方法来完成这项任务,请随时提出建议。

为了测试我从 UpdatePanel Timer 的示例开始的概念,会导致所有面板更新。我按照建议修改了一些东西,并提出了下面显示的代码。

当我执行代码时,我可以选择一个下拉选项并让第二个 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();
    }
}

我正在使用带有 ASP.NET 4.0 的 Visual Studio 2010。
我已经使用 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>
4

1 回答 1

0

我终于明白了这一点。最后,这归结为 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>

这是一个问题的链接,在故障排除时很有帮助,以防万一有人遇到同样的问题:系统未定义

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

于 2013-04-19T17:41:28.923 回答