簡體   English   中英

UpdatePanel計時器觸發器不起作用

[英]UpdatePanel Timer Trigger not Working

我正在嘗試獲取一個計時器來觸發對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();
    }
}

我將Visual Studio 2010與ASP.NET 4.0一起使用。
我已經使用本地主機和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>

我終於了解了這個。 最后,這歸結為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 undefined

感謝所有發表評論的人,他們對我保持前進以及確保我對正確的位置進行故障排除非常有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM