Calling Javascript from a Server side event

Posted on 2006-05-11
Last Modified: 2010-07-27
I need to call a javascript function from an event raised by the FileSystemWatcher object, basically the Watcher watches a directory and updates a screen message and chart to say that new photos have been added, the message must be updated without the page being refreshed and must happen in response to the event and not on a timer. I must admit I've had a look at ajax but it all works the other way around. Desperately need help urgently this think has got to be finished tomorrow.

Thanks in advance

Question by:pj_bennett
    LVL 44

    Expert Comment

    Hi pj_bennett,

    The problem is that it just doesn't work that way! The whole point is that the server cannot communicate directly with the client, therefore there is no way to push information on the client. You have to initiate things from the client and that means a timer or something there. You cannot do it at the server end as there is no way to access the browser itself unless during a post or get operation.

    Tim Cottee

    Author Comment

    So it can only be done using a timer? That's a real problem, that's going to be a big change to the architecture of the application. Any ideas on build this thing so it works as efficiently as possible with a timer?
    LVL 44

    Accepted Solution


    Well, I would look at an ajax solution. Which you could use with a javascript setInterval() function in your page. This can then be used to test whether there is anything to actually do. This would appear transparent to the user viewing the page as there will be no postbacks until something is needed. Then you could use ajax again to pull that information out without refreshing the whole page. Whilst it is still a timer based solution, it is client side and using ajax would appear as if it had updated automatically.


    Author Comment

    I know this is being a bit cheeky but you haven't got any code that does a similar thing in C# have you. Thanks for your help by the way, I've been pulling my hair out on this for a couple of days now. At least I know what originally wanted to do isn't possible



    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    only14 challenge 19 57
    has77  challenge 9 56
    parentbit challenge 3 38
    mapAB Challlenge 35 55
    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now