Click to return to the Essentials home page    
Web Workshop  |  Essentials

How Do I Look?

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.

A-error hunting we will go

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.

TopBack to top

Knock, knock

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[ Hi, I'm the definition ].

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.

TopBack to top

Crank it up

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.

TopBack to top

 


This Month's Hot-Button Issue: Querying Remote Databases

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.0Non-MSDN Online link and that you have the Adventure Works Sample Database, which is available during a custom installation of the Microsoft Data Access Components (MDAC)Non-MSDN Online link. Do you have these? Well, let's do it!

On the Web server

On the Web server, you will need to upgrade to Microsoft Data Access Components (MDAC) version 2.0Non-MSDN Online link. 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 AccessNon-MSDN Online link. 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.

  1. Run the User Manager for Domains (Start, Administrative Tools, User Manager For Domains) Double-click on the IUSR_<MACHINE name> account, and change the password to the IUSR_<MACHINE name> to a known value.
  2. Run the Internet Service Manager (Start, Windows NT 4.0 Option Pack, Microsoft Internet Information Server, Internet Service Manager)
    • Expand the Internet Information Server Folder, your Web server will appear, and you can expand it.
    • Right-click on Default Web Server and select Properties.
    • A dialog box will appear. Go to the Directory Security Tab. Select Edit, Allow Anonymous will be selected. Choose Edit next to this tab.
    • Deselect Enable Automatic Password Synchronization, and select OK until all of the open dialog boxes are closed.

On the remote server

  1. Run the User Manager for Domains (Start, Administrative Tools, User Manager For Domains), and create a new account with the same name as your Web server's IUSR_<MACHINE name> account.
    • Assign the same password that you specified in step 1 above.
    • Deselect user must change password at next log on.
    • Select Password Never Expires
  2. Create a folder where you intend to keep your database (if it does not already exist). Create a share for this folder and give the newly created IUSR_<MACHINE name> account Change permissions for this folder.

On the Web server

  1. Using the ODBC Administrator, create a new System Data Source Name (DSN), which connects via a UNC path to the Remote database in the share created in the previous step 2.
  2. Create a test.asp page to test your database access. This sample assumes that you called your DSN "Remote" in the previous step.
  3. <%@ 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"
    
      &lsquo;
      &lsquo; Change the line below to match your Database Schema
      &lsquo;
    
      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>
    
    
  4. When executed, the above file will return a result set from the remote database.

For other great references on this topic, see the Microsoft Knowledge Base articles Q166029: PRB: Cannot Open File Unknown Using AccessNon-MSDN Online link and Q184566: HOWTO: Set Up Duplicate Anonymous Account on Separate ServerNon-MSDN Online link. Also, check out the Site Builder Network article Authentication and Security for Internet Developers by Scott Stabbert.

Back to topBack to top

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 MVPNon-MSDN Online link program.


The Web Men in Short

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)Non-MS link. The current Extensible Markup Language (XML) 1.0Non-MS link 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 Non-MSDN Online link and Microsoft HTML HelpNon-MSDN Online link 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.

The Web Men's Greatest Hits

List of Web Men Topics



Back to topBack to top

Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.