473,387 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

fire Client Side code from Server Side at runtime

yarbrough40
320 100+
alright now I know this defeats the purpose of client side vs. server side (refer to title of this thread)... What I would love to do is build my own custom progress indicator on the client showing how far a server side code has progressed. I figure if I could only get a JavaScript to fire and render a value of some control at pre-defined intervals while the server is working I could make it happen - but alas I'm beginning to believe that this is impossible. Below is some code that performs three 2 sec loops. At the end of each I want to change the visible value of a control on the browser.

This is a fun one! I'm beginning to believe that it isn't even possible.... If anyone has any ideas I would LOVE to hear them!


Expand|Select|Wrap|Line Numbers
  1.  Dim dt As Date = Now()
  2.         Dim dt2 As Date = dt.AddSeconds(2)
  3.         Do Until Now() = dt2
  4.         Loop
  5.         Response.Write("first Loop complete<br />") '(does not work - waits till postback has finished and all three responses show)
  6.         ''FIRE SOME ALREADY REGESTERED JAVASCRIPT FUNC()
  7.  
  8.         dt = Now()
  9.         dt2 = dt.AddSeconds(2)
  10.         Do Until Now() = dt2
  11.         Loop
  12.         Response.Write("second Loop complete <br />") '(does not work - waits till postback has finished and all three responses show)
  13.         ''FIRE SOME ALREADY REGESTERED JAVASCRIPT FUNC()
  14.  
  15.         dt = Now()
  16.         dt2 = dt.AddSeconds(2)
  17.         Do Until Now() = dt2
  18.         Loop
  19.         Response.Write("third Loop complete <br />") '(does not work - waits till postback has finished and all three responses show)
  20.         ''FIRE SOME ALREADY REGESTERED JAVASCRIPT FUNC()
Apr 13 '10 #1

✓ answered by Aimee Bailey

The easiest way to do this is to save a file on the server, then have your javascript read that file every so often to see how far its got.

I have used this method before, except my server included apache http server so i could read the progress anyware in the world. Note, id stay away from straight flat files, instead use something like xml to give your file a format thats easily readable by javascript, heres an example of writing an xml file in vb.net:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Xml
  2.  
  3.     'The following sub formats and saves an xml file.
  4.  
  5.     Public Sub PublishProgress(ByVal file As String, _
  6.                                ByVal value As Integer, _
  7.                                ByVal maxVal As Integer)
  8.         Try
  9.             Dim iDoc As New XmlDocument()
  10.  
  11.             Dim nodeMain As XmlNode = iDoc.CreateElement("progress")
  12.             Dim nodeVal As XmlNode = iDoc.CreateElement("value")
  13.             Dim nodeMax As XmlNode = iDoc.CreateElement("max")
  14.  
  15.             nodeVal.InnerText = value
  16.             nodeMax.InnerText = maxVal
  17.  
  18.             nodeMain.AppendChild(nodeVal)
  19.             nodeMain.AppendChild(nodeMax)
  20.  
  21.             iDoc.AppendChild(nodeMain)
  22.             iDoc.Save(file)
  23.  
  24.         Catch ex As XmlException
  25.             MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace)
  26.         End Try
  27.     End Sub
You would call something like this everytime the progress changed on your server application, and the client would read that file every so often to see if you had updated it.

Its worth a note that the clue to things like this is in the name "Client" and "Server", unless you have a async data system setup, you'll always have the server providing data, and the client asking weather its available.

Hope this helps!

Aimee.

8 2306
Aimee Bailey
197 Expert 100+
The easiest way to do this is to save a file on the server, then have your javascript read that file every so often to see how far its got.

I have used this method before, except my server included apache http server so i could read the progress anyware in the world. Note, id stay away from straight flat files, instead use something like xml to give your file a format thats easily readable by javascript, heres an example of writing an xml file in vb.net:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Xml
  2.  
  3.     'The following sub formats and saves an xml file.
  4.  
  5.     Public Sub PublishProgress(ByVal file As String, _
  6.                                ByVal value As Integer, _
  7.                                ByVal maxVal As Integer)
  8.         Try
  9.             Dim iDoc As New XmlDocument()
  10.  
  11.             Dim nodeMain As XmlNode = iDoc.CreateElement("progress")
  12.             Dim nodeVal As XmlNode = iDoc.CreateElement("value")
  13.             Dim nodeMax As XmlNode = iDoc.CreateElement("max")
  14.  
  15.             nodeVal.InnerText = value
  16.             nodeMax.InnerText = maxVal
  17.  
  18.             nodeMain.AppendChild(nodeVal)
  19.             nodeMain.AppendChild(nodeMax)
  20.  
  21.             iDoc.AppendChild(nodeMain)
  22.             iDoc.Save(file)
  23.  
  24.         Catch ex As XmlException
  25.             MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace)
  26.         End Try
  27.     End Sub
You would call something like this everytime the progress changed on your server application, and the client would read that file every so often to see if you had updated it.

Its worth a note that the clue to things like this is in the name "Client" and "Server", unless you have a async data system setup, you'll always have the server providing data, and the client asking weather its available.

Hope this helps!

Aimee.
Apr 13 '10 #2
yarbrough40
320 100+
This is exactly the kind of thing I was looking for! totally get it..... I'm on it. Great insight!
Apr 13 '10 #3
Frinavale
9,735 Expert Mod 8TB
If this is an ASP.NET question you may also be interested in checking out this thread: ASP.NET Progress.

-Frinny
Apr 13 '10 #4
yarbrough40
320 100+
Frinny, That is indeed an interesting conversation u had on the subject. I have never used Atlas controls. Is there any issue that you know of using Atlas and Ajax in the same form considering that you will then have two script managers?
Apr 14 '10 #5
Frinavale
9,735 Expert Mod 8TB
You probably shouldn't be using Atlas stuff at this stage.
Atlas was the pre-release/beta stuff that is Ajax.NET

I don't know of any issues but I don't think I'd recommend it either.

-Frinny
Apr 14 '10 #6
yarbrough40
320 100+
got ya! thanks... also - I think this XML route is a good one because it allows the server to quickly set the node value then move on while the browser constantly checks the node independantly. The only issue I could possibly see with this is if you have multiple users running this at the same time posing concurrency issues in the XML. The easy solution is to create a new XML doc each time then blow it away when the procedure finishes. The only issue then that I see is if you have a giant application with a boat load of concurrent users which could potentially create thousands of temporary XML docs that strain the server. Do you have any thoughts?
Apr 14 '10 #7
Frinavale
9,735 Expert Mod 8TB
You're still going to need to use Ajax to make the request either way.

I liked the Session variable approach because a whole file seems overkill to me...and then you have to worry about cleaning up files which sometimes can be a problem if your application is recycled in the middle of processing (leaving files that will never get cleaned up).

It looks like threading did the trick.
I'd return to my code that I posted and try adding in threading but right now I can't...

-Frinny
Apr 14 '10 #8
yarbrough40
320 100+
ok so the XML approach works but I agree with you that using a file is a clunky way of doing this. Interestingly enough when I attempt to set a session variable from within a background thread I get errors telling me that I need to enable session state in the page (which I did indeed do). I also made sure to add this to the web.config

Expand|Select|Wrap|Line Numbers
  1. <httpModules>
  2. <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
  3. </httpModules>
still no dice... this continues to be a pickle!
Apr 16 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Deepal | last post by:
Hi; I'm doing an example program from a book regarding .NET Remoting. Both the Client and Server are C# Console Applications. Server Code is using System; using System.Runtime.Remoting;...
3
by: aaa | last post by:
I fail to see the connection between the code behind and the raw HTML of the ASPX page how do you get variables and functions to communicate with each other? I cannot get this to even fire:...
5
by: Verde | last post by:
This is admittedly an apparently odd request... but please indulge me if you don't mind: Suppose I have two <asp:Button.../> on a page (Button1 and Button2). User clicks Button1 and triggers a...
4
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
2
by: Stuart Whiteford | last post by:
Hi, I asked this back in January without answer and forgot about it until now. I've got a basic web form, two textboxes, a couple of radio button groups, some required field validators, and a...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
6
by: Jon Paal | last post by:
validation doesn't fire what's missing ????? /////// ---- code -----/////////////////////////// Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles...
2
by: erbilkonuk | last post by:
Hi, I am very new to .NET Remoting and I try to run a simple program to subscribe to an event raised by Remoting Class. The Remoting Server initiates an instance of Remoting Class as Singleton /...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.