Calling Javascript from a Server side event

Posted on 2006-05-11
Medium Priority
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
  • 2
  • 2
LVL 43

Expert Comment

ID: 16659382
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

ID: 16659457
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 43

Accepted Solution

TimCottee earned 1000 total points
ID: 16659489

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

ID: 16659531
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Starting up a Project

621 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