Avatar of Relegence
RelegenceFlag for Israel

asked on 

Calling a javascript function from server side, using AJAX timer

Hello,

I am developing a ASP.NET ajax application.
I am using a timer:

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

The only thing I want to do is to call a javascript function on every tick of the timer:

 protected void Timer_Tick(object sender, EventArgs e)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "blink", "<script>blinkit('2');</script>");
        }

This doesn't work.
The javascript function is being called only if I put the 'RegisterClientScriptBlock' in the Page_Load.

How can I call the javascript every couple of seconds?

Thank you
AJAXASP.NET

Avatar of undefined
Last Comment
Relegence
Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Hi,

Don't know about the rest of your code but if you try using:

protected void Timer_Tick(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "blink", "blinkit('2');", true);
        }

it should work depending if you are making a full postback or not (which is needed for this way to work). If You are controlling the contents of an update panel with the timer I guess you need to add the timer as a postback trigger (not async) for the update panel.

/Carl.
Avatar of Relegence
Relegence
Flag of Israel image

ASKER

I am afraid it didn't help.

Below is my code
<form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:Timer ID="Timer1" runat="server" OnTick="Timer_Tick" Interval="5000" />                
            </ContentTemplate>
        </asp:UpdatePanel>  
        <asp:Label ID="lbl" runat="server"></asp:Label>
        <label id="lblHTML">test</label>
    </div>
    </form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Relegence
Relegence
Flag of Israel image

ASKER

Thanks a lot. it works perfectly!!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo