ASP.NET Timer only works in debug mode

久未见 提交于 2019-12-23 09:42:24

问题


I am using the ajax timer control inside an update panel.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>            
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

The timer should update the label every second with the current datetime.

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToString();
    }

Everything works fine in debug mode but when I run the site without debugger (CTRL+F5) or if I deploy the site to my server the timer does not tick.

But when I add "debug=true" to the web.config everything works fine. Even on my server.

<compilation targetFramework="4.0" debug="true">

Internet Explorer throws the exception "Object doesn't support this action" in ScriptResource.axd.

How can I solve this issue?

EDIT: I think I have solved it.

I don't know why but two things can solve this issue:

  • Using a ScriptManager instead of a ToolScriptManager
  • Using the ToolScriptManager with CombineScripts="false"

I have no clue if this is a bug or not.

Maybe somebody can explain it.


回答1:


There seems to be a bug in the latest AJAX Control Toolkit - I have just come across this error myself - It seems the only option is to downgrade to a previous version.

https://ajaxcontroltoolkit.codeplex.com/workitem/27639 and http://forums.asp.net/t/1962717.aspx?Timer+and+Script+Combining+w+ToolkitScriptManager

to fix the current issue i am having to run in debug mode until i can downgrade and test.




回答2:


This worked for me.

Using the ToolScriptManager with CombineScripts="false"


来源:https://stackoverflow.com/questions/21797310/asp-net-timer-only-works-in-debug-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!