Solved

AJAX .NET -- Timer control -- How to call a Javascript function?

Posted on 2008-10-03
1
483 Views
Last Modified: 2013-11-08
Hello,

I have a AJAX.NET Timer control running in a page and it polls the server every 5 seconds.  I need it to call a Javascript function.  Is this even possible?  Any ideas?

In the included code snippet, you'll see that I'm trying to force a write of "alert('hi!');"  That doesn't work, but I need to do something like that.

Thanks
protected void timerPoll_Tick(object sender, EventArgs e)
    {
        Label1.Text = "The time is: " + DateTime.Now.ToShortTimeString();
 
        Literal1.Text = "alert('hi!');";
    }

Open in new window

0
Comment
Question by:sushik15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 22643656
No, that is not possible. You can create javascript from the server side with something like this:

        Page.ClientScript.RegisterStartupScript(typeof(Page), "script1", "alert('Hi');", true);

if you do it while the page is still processing on the server, for instance in the Page_Load handler. The server has to render the script to the browser in the response, just like the other controls. During an async postback, it can't render script to the page.

You could however write a javascript function to do something every five seconds (not using a timer control). its clock would be more or less synchronized with the async timer control, but they would work independently of each other. It wouldn't necessarily occur write after you poll the server. If you want that to happen you would have to write it all in javascript. If you are interested in that you could start by looking here at the timer information:
http://grizzlyweb.com/webmaster/javascripts/refresh.asp

0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question