我正在尝试使用Timer来触发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>
答案 0 :(得分: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>
以下是有关问题的链接,以便在遇到任何人遇到同样问题时进行问题排查:Sys is undefined
感谢发表评论的每个人,他们非常乐于帮助我继续前进,并确保我正在排查正确的位置。