Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling ASP page through ActiveX Control 1

Status
Not open for further replies.

sqlnerd

Programmer
Jan 21, 2003
24
IN
Hi,

I want to call a timer ActiveX control through an asp page and provide the interval dynamically. I want to calculate duration in minutes in the ActiveX control. I also want to do certain action in the asp page when the duration is, say 30 minutes.

When I implement the activex control, shoud i use <Object> tag or the Server.CreateObject. Will the default location Winnt\system32 be OK? after registering through regsvr32, should i do something in the IIS to successfuly use the Server.createobject?

Can anybody out there help me?

Thanx in advance...

SQLNerd
 
Ok, if you do this server-side with CreateObject the page will (by default) timeout after 90 seconds. you can increase this timeout, but that means your holding up resources for your page and not doing anything with them.

If you do this client-side then you could have it change the page address and supply an argument for the querystring, a simple if check against the value fo that querystring in your ASP page will allow you to execute any portion of the script you want based on the presence of that value.


Note: Timers are generally not a good idea in ASP, even the 5 or 10 second variety. A 30 minute timer would be very bad, especially if several people opened the page at once. Perhaps if you tell us what your trying to do we might be able to provide a better solution.

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
Tarwn,

Sorry! I think I have messed up things a bit. I dont want to increase the timeout limit. I do some calculations in my asp page and i have a button which when pressed reloads the page and proceeds with the calculations (I use session variables and change their value whenever i click the button). Now i want to run the ActiveX parallelly (like a thread). When i run the asp page the first time, i will pass the duration (in minutes, a value from a database field) to the activex.

I plan to implement the standard Timer VB control in my activex. I will add up the interval of the timer control. When it reaches the duration passed from the asp page, i want to display a warning message and redirect to another asp page.

Will this logic work?

SQLNerd
 
Unfortunatly no. When you request an ASP page the server runs the script for that page, sends the Response buffer to the user, and then cleans up a objects or variables in memory. Objects don't stay alive from one request to the next unless you instantiate them in the session or application layers.
You would have the same problem with a client-side activeX object. When the page changes or is reloaded an new copy of the object would be created (if it was included in every page).

While it would be possible to instantiate a timer in the Session_OnStart, you would only be able to check it while processing page requests. Since that is the case it would be just as effective to store a start time in a session variable and simply use DateDiff to compare it to Now every time you wanted to check the elapsed time.

This solution will not be as exact as having a threaded timer running, but since it isn't possible to send the user Response data without a Request, you wouldn't really be able to have a timer force a new opage on the user from the server without them having requested a new one.

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
hmmm... OK... It seems its a dead end... let me break my head and do some lateral thinking...

anyway thanks a lot Tarwn...

-SQLNerd
 
Oooh, Idea :)

You could have a javascript function inside your pages to handle the redirection. When they first visit your pages store the time, figure out the time you want the redirect to occur, store that as well.
With each page put a SetTimeout in the body OnLoad attribute and find the number of milliseconds by using DateDiff in your ASP code. This basically sends the page to the user ticking down until the final redirect. If they change the page before that timout runs out, but you have included the timeout code in every page, then the next page could have a timeout also figuring out the remaining time using DateDiff, so it would continue to count down.

The only issue you would run into is latency across the line. The timeout wouldn't start running until the page fully loaded. You could get around this by not placing it in the OnLoad (sorry, train of thought).

So here is how you would set up the pages:
Code:
1) Check if there is a session variable set for start time, if not, then set it.
2) Determine how long your going to wait - use DateAdd to create an EndTime and store this in a session variable
3) In Each page do a DateDiff between the stored End Time and Now. Output a small javascript block with a SetTimeout (using the seconds from DateDiff*1000 and the name of your redirect function) and your redirect fuction (which could also contain an alert to tell the user what is happening)
4) Response.Flush to send this data immediately to the user.

Now you still have a minor loss of a couple seconds due to the time it took that snmall piece of javascript to get from the server to the client, but I don't think your going to get much more exact.

Let me know if any of this doesn't make sense, I know I rambled a bit up there :p

-Tarwn
Now when

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
OK Tarwn... let me try to implement and see if it works...

SQLNerd
 
Tarwn,

Great!!! It works... Thanks a lot...

lo... finally this could be solved at the client-side itself through javascript...

SQLNerd
 
I'm glad it worked for you, I thought my explanation might be a bit to convoluted for what I was trying to explain, but glad you managed to work it out :)

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Do you know how hot your computer is running at home? I do
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top