Jeff Brown
Rafael M. Muñoz
Microsoft Corporation
October 5, 1998
Updated November 4, 1998
this document (zipped, 10.6K)
The following article was originally published in the Site Builder Magazine (now known as MSDN Online Voices) "Web Men Talking" column.
Contents
A-error hunting we will go - JScript error handling
Knock, knock - Displaying glossary definitions
Crank it up - Trying to improve data-binding performance
This month, the Web Men find in their mailbox questions about display, or how to make stuff look good. Always conscientious, they explain how to show word definitions in a glossary. And keeping in mind that things are not always what they seem to be, our answer guys address less visual issues, such as error handling and data-binding performance.
Dear Web Men:
My question is a simple one, heard that one before? I am using JScript and was wondering if JScript had a way of catching errors. I know that VBScript has "on error resume next", so what is the JScript equivalent?
Tina Wilhelm
The Web Men reply:
You know, Tina, when you see as much e-mail as we do, the simple ones are sometimes harder than you might think. In this special case, yours is a pretty easy question, though definitely a hot one; we've seen the exact same question many times in various internal aliases.
Unfortunately,the answer to your question currently is, No. The current version of JScript does not have a way to directly catch errors. If we look into the future -- let's say around the time of Internet Explorer 5 and JScript 5.0, which are both currently in beta -- the answer to your question will be, YES.
JScript 5.0 will have a "try . . . catch statement". If you download Internet Explorer 5.0 Developer Preview Release, you'll also get JScript 5.0 and you can then play with exception handling. Or you can just download the JScript 5.0 scripting engines and test things out that way.
What to do about the here and now? Remember, we said that JScript does not directly catch errors. Through the use of Visual Basic® Scripting Edition (VBScript) we can create a workaround to this problem. The following code provides an example of what we mean:
<% @LANGUAGE=jscript %> <SCRIPT LANGUAGE=vbscript RUNAT=server> function trap_call on error resume next trap_call = DO_CALL_THAT_CAN_RETURN_ERROR() if 0 != err.number then trap_call = err.description; end if end function </SCRIPT> <HTML> Catch me an error: <%=trap_call();%>. </HTML>
In our sample code, you can see that we are setting JScript, in the first line, as the default language throughout our Active Server Pages (ASP) page. We then create a VBScript function, and force it to run on the server by using the RUNAT attribute. This alleviates the problem of the client machine not having the VBScript engine installed.
The VBScript function, trap_call, then handles the function call that could possibly cause an error, and the "on error resume next" statement will handle the rest. Just replace DO_CALL_THAT_CAN_RETURN_ERROR() with a function call that you want to test for error return codes.
For more information, read Michael Edwards's article Microsoft JScript Version 5.0 Adds Exception Handling. Happy error hunting, Tina.
Dear Web Men:
Hi there,
I have been looking for a solution to my problem, knocking on everybody's door -- but so far, no result, you are my last resort.
I am working on a CD-ROM project -- and to visualize the documents, I am using an OCX of Internet Explorer 4.0. The documents are in SGML; I have broken down the main bulk of SGML into small granules and converted these granules into HTML.
These small granules contain words that should appear in the glossary. So what I want is when my mouse passes over one these words, the definition of this word appears in a pop-up window. The definitions of the words are in a separate file.
I would like to know what are the steps to follow to achieve my goal and if you have any sample code for something similar. Is this possible to do with DHTML and/or JavaScript?
Wahid Mohamudbucus
The Web Men reply:
Wahid, we don't want you to have to keep pounding on doors, like an annoying door-to-door salesman. Let's see what we can do.
When converting the SGML to HTML, consider pulling the definition of the words into the content where they are referenced. You could maintain a separate file for a shared glossary for your project, but an additional step when converting the content would be to look up the word for its definition in the glossary, and include the definition right in the content.
Since the definition for a given word should not change (or at least not frequently, and not while someone is looking at the page), there is no reason to store it in a separate file at run time. Referencing the definition in a separate file, and having to load the separate file, is really more overhead than is necessary.
One possibility for displaying a definition using Dynamic HTML (DHTML) in Internet Explorer is to use the TITLE attribute. If you assign text to this attribute for an element, it diplays the text in a ToolTip (a small yellow window) when you move the mouse cursor over the element. See what we mean by pointing to this word.
Here is the HTML used in the previous sentence:
See what we mean by pointing to this <SPAN STYLE="cursor:hand;text-decoration:underline" TITLE="Hi, I'm the definition">word</SPAN>.
The issue with this ToolTip approach is that the window is only displayed for a fixed amount of time. If a definition is long, the window may not be displayed long enough for the person to read it. You don't have control of how long the window is displayed, and you don't have control of the appearance of the window.
Another approach is to nest elements, and use some scripting to change the visibility or Cascading Style Sheets (CSS) display property of the definition when the user mouses over the word. See what we mean by pointing to this word.
Here is the HTML and script used in the previous sentence:
See what we mean by pointing to this <SPAN STYLE="cursor:hand;text-decoration:underline" ONMOUSEOVER="this.children(0).style.display=''" ONMOUSEOUT="this.children(0).style.display='none'">word <SPAN STYLE="display:none;text-decoration:none; background-color:lemonchiffon"> [ Hi, I'm the definition ]</SPAN></SPAN>
The previous example uses the display property to include the definition inline with the word when the user mouses over the word.
Hopefully, these examples give you some ideas. In both cases, you could probably generate a script to create the DHTML for definitions as part of your content conversion process.
For more information about DHTML, check out the DHTML, HTML & CSS section of the Web Workshop and read Michael Wallent's monthly column, DHTML Dude.
Dear Web Men:
I'm working on a project that sounded like it would be perfect for DTHML Data Binding. I'd like to take a large table of data and dynamically switch between three or four different views. Instead of re-building the tables on the server, I thought I would give data binding on Internet Explorer 4.0 a try. Unfortunately, the performance of the layout engine looks like it's an <n squared> sort of time frame. Assuming that I have to format my data with a table, is there any way that I can boost Internet Explorer 4.0's performance?
Benjamin Pate
The Web Men reply:
Unfortunately, we don't have any breakthrough ideas here. You probably will need to get creative if you want to present a bunch of different views of the same data, and the database tables are very large.
One way to boost performance is to limit the number of records that are displayed in the tables by setting the DATAPAGESIZE attribute (or dataPageSize property). By default, all the records for your data set will be displayed in the table. When you set this attribute or property, you can control how many records are displayed in the table at one time. For more information and a sample, take a look at Optimizing Table Viewing with the DATAPAGESIZE Attribute in the Web Workshop.
Maybe you can reduce the number of fields and records you need to see at one time. And maybe you can reconsider -- is it critical to see a large set of records all at once in a table format?
You could display a smaller set of records and fields in a different HTML element, other than a table, and then summarize the larger set of data using grouping in the database query. Remember that you can have several different HTML elements on the page bound to different (or the same) data sources. These are some other options to consider.
As a side note, in Internet Explorer 5 Developer Preview Release, there have been performance improvements made in rendering content, including something called fixed layout tables. However, in the case where you are using data binding in a table, using fixed layout tables will not gain you much more in terms of performance. For more information about performance improvements and new features in the next version of Internet Explorer, check out the article Internet Explorer 5: The Overview for Site Builders.
Each month, the Web Men ask Microsoft Developer Support to pick the most burning issue they're hearing from Web developers. This month, Jeff Sandquist looks at querying an Access database located on a remote machine:
Let's reach out and touch someone -- or better yet -- a remote database. Querying an Access database located on a remote machine from ASP can be tricky, but not impossible. Just follow these simple steps, and you'll notice nothing up my sleeve.
This article assumes you are using Internet Information Server (IIS) 4.0 and that you have the Adventure Works Sample Database, which is available during a custom installation of the Microsoft Data Access Components (MDAC). Do you have these? Well, let's do it!
On the Web server, you will need to upgrade to Microsoft Data Access Components (MDAC) version 2.0. If you tried accomplishing this with the previous versions of MDAC (1.5a, b, c), you probably encountered a bug that would not allow you to do this, Q166029: PRB: Cannot Open File Unknown Using Access. However, this bug has been fixed in MDAC version 2.0.
Accessing the remote server requires a two-step authentication process: First, the user is authenticated on the Windows NT® server where the Web server is running, and then the user is validated on the machine where the database resides. The Windows NT Web server requires a valid user account and password to be set up inside NT User Manager (in this case, the Anonymous account IUSR_<MACHINE name>). The remote server where the database resides requires a duplication of the IUSR_<MACHINE name> account to be setup as well.
<%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <% dim cnn dim rs set cnn = server.CreateObject("ADODB.Connection") set rs = server.CreateObject("ADODB.Recordset") cnn.Open "dsn=Remote" ‘ ‘ Change the line below to match your Database Schema ‘ rs.Open "select * from Products", cnn do while not rs.EOF Response.Write rs(0) & "<br>" rs.MoveNext loop rs.Close cnn.Close set rs = nothing set cnn = nothing %> </BODY> </HTML>
For other great references on this topic, see the Microsoft Knowledge Base articles Q166029: PRB: Cannot Open File Unknown Using Access and Q184566: HOWTO: Set Up Duplicate Anonymous Account on Separate Server. Also, check out the Site Builder Network article Authentication and Security for Internet Developers by Scott Stabbert.
Jeff Brown, when not forcing family and friends to listen to Zydeco and country blues music, manages the development of the viewer and authoring tools for the Microsoft Mastering Series.
Rafael M. Muñoz is a part-time Adonis, and full-time support engineer for Microsoft Technical Support. He takes it very, very personally every time you flame Microsoft.
Jeff Sandquist (one of Microsoft's finest Canucks) is a member of Developer Support's Active Server Pages Escalation Team and Commander in Chief of the Visual InterDev MVP program.
October 5, 1998
Q: Phil Dawson can't begin his XML Document Type Definition (DTD) ID attribute with a number.
A: Microsoft's support of XML follows the standards put out by the World Wide Web Consortium (W3C). The current Extensible Markup Language (XML) 1.0 standard states that an ID attribute can not begin with a number.
Q: Garrett Siegel wants to set the user's home page in Internet Explorer.
A: Refer to our short answer in our November 1997 column.
Q: Jace Finman asks what data is stored in the today variable of the DHTML Clock sample.
A: The DHTML Clock sample's today variable is a Date object and contains methods for obtaining date information.
Q: Frank Rachel wonders what tools Microsoft uses to create online documentation.
A: Different Microsoft product teams use a variety of tools, some of them proprietary. But Microsoft Word and Microsoft HTML Help are often used.
Q: Chad Pelander wants to have Internet Explorer 3.02 and Internet Explorer 4.01 on the same machine.
A: Refer to Barney finds new life in our December 1997 column.
Q: Mike Garoutte asks how some of the MSDN Online Web site features were implemented.
A: See Building a Better Workshop in the MSDN Online Voices.
Q: William G. Grosskopf is is looking for some expert help on a Web project.
A: Check out the MSDN Online Members Helping Members.
Q: Victor Rebouças wants to run VBScript or JavaScript directly within the operating system, not through a Web browser (we think).
A: Use the Windows Scripting Host. See the Microsoft Scripting Technologies.