asp.net ajax timer RegisterStartupScript issue

Last post 08-04-2008 11:45 PM by vgiambattista. 4 replies.

Sort Posts:

  • asp.net ajax timer RegisterStartupScript issue

    08-02-2008, 6:47 PM

    I have an asp.net timer control on a page that needs to fire a javascript event on Tick event.  I can normally fire a javascript call using ClientScript.RegisterStartupScript, etc. and I have event tried to fire one on the ScriptManager.RegisterStartupScript within the Tick event.  I get the infamous "Sys.WebForms.PageRequestManagerParserErrorException" exception. 

     Has anyone got an example of calling a RegisterStartupScript(or calling/running a javascript function from the server methods) on the Tick event of the timer control?

     

    Joseph Baggett

    http://www.myitstudio.com




    MCSD, MCPD: Web Developer, MCITP: Database Developer, MCTS: SQL Server 2005, MCTS: .NET 2.0 Web Applications, MCTS: .NET Framework 2.0 Windows Applications, MCTS: .NET Framework 2.0 Windows Applications, MCAD, MCP

    If the project doesn't work, blame Scott Guthrie and/or refer to the problem solving flowsheet. O.~
  • Re: asp.net ajax timer RegisterStartupScript issue

    08-03-2008, 5:33 PM
    Answer

    Joseph,

    Here is the working barebones implementation:

            protected void Timer_Tick(object sender, EventArgs e)

            {

                ScriptManager.RegisterStartupScript(this, typeof(Page), "alertBox", "alert('hi');", true);

            }

    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <div>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

    <ContentTemplate>

    <asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer_Tick">

    </asp:Timer>

    </ContentTemplate>

    </asp:UpdatePanel>

    </div>

    </form>

     

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: asp.net ajax timer RegisterStartupScript issue

    08-03-2008, 7:18 PM

    Thanks, worked like a dream.  Say hi to Rockford Lhotka. 

    Joseph Baggett

    http://www.myitstudio.com




    MCSD, MCPD: Web Developer, MCITP: Database Developer, MCTS: SQL Server 2005, MCTS: .NET 2.0 Web Applications, MCTS: .NET Framework 2.0 Windows Applications, MCTS: .NET Framework 2.0 Windows Applications, MCAD, MCP

    If the project doesn't work, blame Scott Guthrie and/or refer to the problem solving flowsheet. O.~
  • Re: asp.net ajax timer RegisterStartupScript issue

    08-03-2008, 8:29 PM
    • Star
      13,605 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,248
    • TrustedFriends-MVPs
    If you're using the Timer purely to trigger JavaScript code, you should consider using setInterval instead.
    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: asp.net ajax timer RegisterStartupScript issue

    08-04-2008, 11:45 PM

    Joseph,

    Next time I see him, I will.  He says he might come to Atlanta for DragonCon, but we'll see.  Everyone calls him Rocky, by the way.  I don't think I quite have the nerve to try "Rockford" on him.  ;)

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
Page 1 of 1 (5 items)
Microsoft Communities