Link to home
Create AccountLog in
Avatar of CHAExchange

asked on

ASP/Javascript: Program execution not working unless user input is supplied in the middle of page load.

Hi.  I have a an ASP program that doesn't work, unless I have a javascript alert, embedded in the asp, in the middle of execution.  Here is my program flow:
Page 1 is my main page

During Page1 Load -> calls Page 2 to load into a page1 frame
Page1 OnLoad() -> calls Page 3 to load into a page1 frame
Page3 ->calls Page 4

This program executes correctly if I put an alert() in Page 2.  It also executes correctly if I have a 'dummy' modal window open with a button, and the button is clicked by me (the user), which closes the window.  It doesn't work if I modally open the window and programmatically click the button to close the window.  If I take out the alert or dummy page, I error out on page 2 (error:  object does not support this property or method (URL))  This error occurs on the line where I am setting the workspace for the frame.

I guess what I am trying to figure out is what is happening when I force user input in the middle of execution.  Are the order of events changing???  Any thoughts appreciated!

Avatar of NeoDiffusion
Flag of France image


Sounds like you have a timing issue, and poping up an alert box do solve this. I guess your alert is placed before the offending command, isn't it?

Your error is in page2, but what are you doing in page2? Do you refer to page1 by chance (which is not fully loaded...) ???

Avatar of CHAExchange


Yes, I guess I am trying to write back to the page before it is loaded.  But why does the alert or user input before the write back to page1 alow me to do that?

It's working with a popup because it's just a timing issue: your write back is postponed until user close popup, several ms or seconds later... thus after page 1 is finally loaded.

What you can do to solve this:
(Note: you may have to finetune, I could not test this code yet)

either trigger the action on page2 by a call placed in the onload() within page1.
Something like
(in page1)
<body onload("parent.page2.document.start_it()")>
(assuming your frame for page2 is called page2).

Or use a semaphore: change a value in a hidden form parameter within page2, like:
(in page2)
<form name="sem">
<input type="hidden" name="page1loaded" value="0">

and (in page1)
<body onload("parent.page2.document.sem.page1loaded.value=1")>

Then in page2, loop until page1loaded value is not zero anymore... should do the work.


It's not a timing issue, as in time elapsed.  I know this because I replaced the alert with a javascript loop, that loops for 15000 ms (15 seconds), and I still got the same error.  I have fixed the issue by changing the way I execute the pages, but I would still like to understand what was happening.
Then very strange... no additional suggestion on my side, sorry.

Glad to read that it's working now anyway!

Avatar of Computer101
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account