Q I am developing an ASP application in which the user enters some information in screen A. After processing this information, I display screen B. But the processing sometimes takes a while, so I want to display a screen between A and B that says "Please wait..." or " Processing....". In the interim, Iï¿½ll do the processing while that screen is displayed, then automatically switch to screen B when ready. I want to avoid any client-side scripting, so I need to process the information on the server and pass it to the client when itï¿½s ready.
A First of all, youï¿½re lucky a timeout message is not being generated on the client during processing. In the April issue of MSDN Magazine I addressed the issue of unsightly timeout errors popping up while the browser is waiting for a process. With that warning in hand, I can tell you that one way to present an interim screen is to use a frameset in which a very small (1 px by 1 px) frame was connected to the ASP code doing the processing. That ASP code would use the
statement to turn on Keep-Alive for that page. This will maintain the connection to the server for this page without it timing out. In the main frame of the page you would display the "Please wait..." message. Then, when the hidden page finishes its processing, it could return script code to reset the main frame or point the entire frameset to the report page. Of course this assumes the browser can execute whatever script you return.
<% response.buffer = true %>
Q Okay, Iï¿½ve implemented the solution you suggested, but Iï¿½m still having some problems using the frames. Page A submits data to page B for processing. Page B has a frameset with two frames. One has the data that was posted from page A, and the other displays a simple HTML page that says "Please wait while we process your data...." But when the processing is complete in one frame I want to close the "Please wait" frame. Is it possible to close one child frame from another?
A From a frameset window, you canï¿½t just close one of the windows. Instead, you have to open a new page with the target set to _top or _parent. This will load a new Web page into the place where the frameset had been defined. Suppose you have a two-frame page, where one frame contains one.html and the other contains two.html. One.html looks like this:
When the user clicks on the link, it would appear to them that the frame containing one.html had closed down, leaving two.html. If you want this to happen when some calculation is completed, you could use something like:
<a href="two.html" target="_parent">click</a>
Then you would just have to execute the script code
<a href="two.html" target="_parent" name="clicker"
which would behave as though the user clicked on that link.
Another way is to start the processing in the background on the server, separate from the actual creation of the Web page. Then your ASP could simply request the current status of the process and report that information to the client using a refresh metatag querying the server every 10 seconds or so. Once the processing was complete, you could return the full report page.
A If I read your question correctly, you are trying to use the file upload capability in MicrosoftÂ® Internet Explorer. Before uploading the file to the server, you want to report the file size to the server. To do this with regular scripting, youï¿½d have to gain access to the client file system, which is off-limits to Web pages.
There are several ways to do this. One is to create an ActiveX control. This control, being a regular executable, would have full access to the system and file properties on the clientï¿½s machine. It could fetch the file size and expose this information to your Web page via a scriptable interface. Your Web page could then use that information appropriately.
Another way to do this is to change the extension of your HTML file to .hta. This essentially turns your Web page into an HTML executable, giving it full access to the client system. Downloading an HTA file is identified as being insecure, so this solution will present the same warnings to the user that are presented when downloading an ActiveX control. But unlike an ActiveX control, an HTA file canï¿½t be digitally signed, so to the user it will seem even more dangerous. However, it will be able to use the File object, from which you can get the size of a particular file.
For more information about HTA files, check out the article "Writing HTML Applications for Internet Explorer 5.0," by Scott Roberts, in the July 1999 issue of Microsoft Internet Developer.
For information about the various file system objects, check out http://msdn.microsoft. com/scripting/vbscript/doc/vbsfsoTOC.htm.
Q Is there a way to detect the bandwidth of a Web site visitorï¿½s connection? I want to automatically redirect users to either a slow or fast version of my Web site.
A If there were a way to automatically detect bandwidth, we wouldnï¿½t be seeing all of those Select Bandwidth links on streaming media playback sites.
This doesnï¿½t mean that it is impossible to detect the bandwidth; only that it isnï¿½t something available directly through the normal HTTP connection information. The only direct information you have access to when a user connects to your site is what comes in the HTTP header. This includes USER_AGENT, REFERRER, and a number of others. There is no information in the header that denotes the bandwidth of the client.
You can see all the data in the HTTP headers by adding
to your ASP page, which will dump out all of the data in the headers received by the server session. To determine the userï¿½s bandwidth would require you to find out how fast the client was able to download information from your server. To see an example of this, check out http://computingcentral.msn.com/topics/bandwidth/speedtest.asp.
Speed Test is a simple set of pages that will attempt to detect your bandwidth. It doesnï¿½t do anything fancyâ"it simply retrieves a Web page with a big comment block in it from the server. Right before the comment block is a script call to request the current time, and right after the comment block is another script call to request the time again. By comparing these two values, it determines how long it took for the data of the comment block to download to the browser. From this it estimates the bandwidth. Itï¿½s not perfect or foolproof by any means, but itï¿½s useful for suggesting the bandwidth the user should select. Of course, this test also takes a little time to complete.
It is also possible to write an ActiveX control that interrogates the userï¿½s system to find out what the bandwidth appears to be. This could get tricky, though, depending on the complexity of the userï¿½s connection setup.
A commercial product that does this would have to be either an ActiveX control, a Java-language applet that spins some data back and forth until it can determine the data rate, or something like the Speed Test Web page.
Iï¿½m thinking about trying something like the Speed Test page to help users select the right bandwidth when they view my show (http://msdn.microsoft.com/theShow). As long as they let the page sit for a couple seconds while the calculations are being performed, I could get the estimated bandwidth, then highlight the recommended bandwidth to select. But I would still allow users to choose for themselves. Sometimes I select the low-bandwidth option even when I am on a high-bandwidth connection. Thereï¿½s no sense in making my little laptop work up too much of a sweat.
Q In one of my ASP files, I provide data to the ASP by calling a middle-tier DLL. Sometimes the data stream stops in the middle and returns "ASP error: Unexpected Trappable Error." I donï¿½t know how to trap this error. Iï¿½m using eight arrays in my page. Does this cause a memory problem?
A The error could be in the DLL that you mention, or in your JScriptÂ® code. To debug into the DLL, you would need to be the author of this DLL (or have access to the code), and be running it in debug mode.
When I run into problems like this, I usually attempt to sneak up on the error and find out where my code is doing something that either causes the error directly or brings about an error within the foreign DLL. With a properly designed debugging environment set up, you can use Visual InterDevÂ® to trace through the program. Another option would be to open a file at the beginning of the ASP code, then periodically write out a short statement to the file indicating where you are in the code. Allow the code to crash, then look into the file and see how far you got. This can sometimes require a bit of trial and error. Sometimes you may notice that you sent something improper to the DLL, and this was the root of the problem (for example, sending an object reference to a program that was expecting a pointer to an array).
If you still donï¿½t see the actual problem, but you think you see approximately where the problem occurred, you can build a minimal sample thatï¿½s capable of causing the same error. Make the code as short as you can, then look closely at what you are doing with the code you are calling into, and try a couple of variations to see if you can find a way to accomplish your task without crashing the DLL.
Q Iï¿½ve set up a Web page where a user can fill in information, print it, and mail it. But I would like to make this task easier for users, letting them use e-mail. I can do this in an ASP page, but my Web provider doesnï¿½t allow them.
A There are a few ways to accomplish this. The easiest is to use a Web server that has mail services installed on it that will let you generate e-mail directly from that server on behalf of the user. As you know, this is not an option many servers allow. But somebody has to generate the e-mail, and if it isnï¿½t the server, then it must be the client.
While there might be compatibility issues with the browser, as well as with the e-mail client, I have found that a mailto action on a <form> works pretty well. This will package the form fields into an e-mail message and send them to an e-mail account you specify. The code would look something like this:
This would generate a full e-mail message and send it out from the userï¿½s machine (with a warning posted to the user that it was doing this).
<form METHOD="POST" ACTION="mailto:firstname.lastname@example.org?
subject=A Form Submission" ENCTYPE="text/plain">
Name:<input TYPE=TEXT NAME="Name:"><br>
State:<input TYPE=TEXT NAME="State:"><br>
eMail:<input TYPE=TEXT NAME="Email:"><br>
<input TYPE=SUBMIT value="Submit"><br>
<input TYPE=RESET value="Reset Form"><br>
Q I have an ASP page that builds a listbox of items that are being processed. The page has Submit buttons that allow the user to select the previous and next pages. The code works well except that the current listbox selection can scroll out of view. Is there some way to move the selected item to the top of the listbox?
A Well, thereï¿½s good news and bad news here. The good news is that Internet Explorer 5.0 will automatically scroll a selection list to the item that has the SELECTED property set. The bad news is that neither Internet Explorer 4.0 nor Netscape Navigator 4.0 will do this.
However, Internet Explorer 4.0 and Netscape Navigator 4.0 will do this on dropdown lists (with <select size=1ï¿½>). The bad news is that they wonï¿½t do this for <select> elements with a size greater than 1.
You can, however, force Internet Explorer 4.0 to move to the currently selected item with the following script code:
But this wonï¿½t work with Netscape Navigator 4.0 (nor would anything else I tried) and I couldnï¿½t find a solution that did work.
var obj = document.FormName.ObjName;
var x = obj.selectedIndex;
obj.selectedIndex = 0;
obj.selectedIndex = x;