Printer Friendly Version      Send     
Click to Rate and Give Feedback
Related Articles
Here is an ASP.NET AJAX data-driven Web application that takes the best features from server- and client-side programming to deliver an efficient, user-friendly experience.

By Bertrand Le Roy (October 2008)
Andrew Dai of the CLR team discusses the Transparency model, which creates a strong isolation boundary between privileged and unprivileged code for Silverlight apps.

By Andrew Dai (October 2008)
Learn how to use Windows Presentation Foundation (WPF), XAML, and the deep XML support in Visual Basic to generate user interfaces dynamically.

By Beth Massi (October 2008)
There’s a strong similarity between Web-based Silverlight 2 applications and desktop WPF applications. Enabling easy code reuse between the two is Dino’s focus here.

By Dino Esposito (October 2008)
More ...
Articles by this Author
After receiving a late-breaking news bulletin at magazine headquarters early this month stating that the Web is just a fad that will never amount to anything, we have reluctantly decided to retire our venerable Web Q&A column and replace it with one we like to call Dev Q&A.

Edited by Nancy Michell (January 2006)


Edited by Nancy Michell (November 2005)


Edited by Nancy Michell (September 2005)


Edited by Nancy Michell (July 2005)


Edited by Nancy Michell (June 2005)


Edited by Nancy Michell (May 2005)


Edited by Nancy Michell (April 2005)


Edited by Nancy Michell (March 2005)
More ...
Popular Articles
In this excerpt from his upcoming book, Laurence Moroney explains the basics of Silverlight animation and the animation tools available in Expression Blend.

By Lawrence Moroney (August 2008)
Learn how you can peer-enable business applications by allowing them to share state in a serverless peer network.

By Kevin Hoffman (July 2008)
This article presents an overview of the motivation behind new techniques that decompose problems into independent pieces for optimal use of parallel programming.

By David Callahan (October 2008)
Learn how to create a workflow that uses InfoPath forms and other office documents for passing data to targeted activities and for use in Office documents.

By Rick Spiewak (June 2008)
More ...
Read the Blog
Well designed code keeps things that have to change together as close together in the code as possible and allows unrelated things in the code to change independently, while minimizing duplication in the code. In the October 2008 issue of MSDN Magazine, Jeremy Miller shows you some design ...
Read more!
The process for ink capture and analysis on the Tablet PC is straightforward in managed code. To the uninitiated developer, however, creating unmanaged Tablet PC applications can be rather daunting. In the October 2008 issue of MSDN Magazine, Gus Class a quick introduction to the Tablet PC ...
Read more!
Multicore systems are becoming increasingly prevalent, but the majority of software today will not automatically take advantage of this additional processing ability. And multithreaded programming, for anything but the most trivial of systems, is incredibly difficult and error prone today. In the October 2008 issue of MSDN ...
Read more!
Concurrent programming is notoriously difficult, even for experts. You have all of the correctness and security challenges of sequential programs plus all of the difficulties of parallelism and concurrent access to shared resources. In the October 2008 issue of MSDN Magazine, David Callahan describes ...
Read more!
A major advantage of AJAX and Silverlight applications is that they can transparently and continuously interact with a back-end service. The problem is that they run over HTTP, which wasn't designed with security in mind. In the September 2008 issue of MSDN Magazine, Dino Esposito shows you ...
Read more!
Unhandled exception processing shouldn't be a mystery. It's actually quite useful since it gives a crashing application an opportunity to perform last-minute diagnostic logging about what went wrong. In the September 2008 issue of MSDN Magazine, Gaurav Khanna discusses how ...
Read more!
More ...
From the August 2001 issue of MSDN Magazine
MSDN Magazine
Include Files, ActiveX DLLs, Target a Window in JScript, Cancel a Form Submission, and More
Edited by Nancy Michell
Download the code for this article: WebQA0108.exe (36KB)
Q I'm having trouble getting my include files to work. When I use the include file syntax
<!--#include file="Homepage\toolbar.asp"--> 
the toolbar.asp file is included, but the images in the toolbar.asp file are missing. The same thing happens when I use the include virtual syntax.
<!--#include virtual="/homepage/toolbar.asp"-->
The images are stored in an images directory in a subfolder, and when I view the toolbar.asp file in Microsoft® Internet Explorer, all the images are visible, so obviously they're mapped correctly.

A What's happening here is that after you include toolbar.asp, the image paths are incorrect. For example, if you have a page called /mypage.asp that includes /homepage/toolbar.asp, and toolbar.asp has a line
<img src="images/something.gif">
the browser will look for the file /images/something.gif, rather than the file /homepage/images/something.gif, which is what you were expecting.

Q I have an ASP page with an ActiveX DLL that is presently using an <OBJECT> tag.
<OBJECT ID="myDLL"CLASSID="clsid:8452139D-B179-47CC-9EE4-C5F6E49AB4AB"
  codebase="http://<% =Request.ServerVariables("SERVER_NAME") %>/cabs/
  myDLL.CAB#VERSION=1,0,17,0" 
  height=0 width=0 VIEWASTEXT>  
My client-side JScript® code returns a script error if the ActiveX® DLL didn't install correctly. What is the easiest way to determine if the ActiveX DLL was installed and registered correctly? I have to support Internet Explorer 4.0 and Netscape 4.x, so I can't use try�catch. I have tried a couple of different if statements including typeof(myDLL), which always returns "object" and (!myDLL), which always returns false.

A You should try the following code, replacing oControl with your OBJECT ID.
if ("undefined" != typeof(document.all("oControl")) && 
    null != document.all("oControl").object) 
{
    // The control is installed
}
else 
{
    // The control is not installed
}
Of course, you know ActiveX controls and OBJECT tags don't work in Netscape, so you'll need to handle those cases by sending them a different page.

Q Do you know of any way in JScript to jump to an anchor at the bottom of the page after 10 seconds have elapsed? In other words, is there a scripting equivalent of the following HTML statement?
<meta http-equiv="redirect" content="10; URL=#bottom">
A Sure. In a script block, just use a window.setTimeout using the anchor at the bottom of the page as the href, like so:
window.onload = function()
{
    window.setTimeout("document.location.href='#bottom'", 10000)
}
Make sure you remember to put the anchor at the bottom of the page where you want the link to jump to, like this:
<a name="bottom">
Q I seem to remember reading about a way you can either force or cancel the submission of a form using VBScript or JScript. Now I can't seem to find where I read about it.

A You can validate the user's data with client-side script before actually sending the data. In order to abort the form's submission, you need to hook up an event handler function such as onsubmit, like so:
<form name="form1" onsubmit="return ValidateForm(this);">
      You can read the entire document on this subject at http://msdn.microsoft.com/library/en-us/dncodecorn/html/corner111799.asp. The information pertinent to your issue is at the bottom of the page under the heading "Validating User's Data Before Submitting the Form."

Q I'd like to bulkload my database from an XML file. I'm very new to SQL Server™, so I have a few questions. Can I bulkload using Enterprise Manager? All of the examples in the help file use Visual Basic®. Will BULK INSERT work? I'm attempting to use FOR XML AUTO to get an idea of what the XML file should look like. The query works fine, but I get a syntax error in the FOR XML AUTO area when I attempt to save the view. Adding XMLDATA to the FOR XML line causes a "Failed to Parse Query" error. The XML output in Enterprise Manager goes to a single cell in the output pane. I have to copy and paste into something else to see what has happened. Figure 1 shows the query and output.
      Also, I have an existing empty database that I want to fill from XML. Is there a way to get the database to generate the mapping schema, or do I have to create the mapping schema by hand?

A SQL Server has three kinds of XML features. First, there are all the things out there that people have used in the past to construct XML from relational data (like ADO recordsets).
      Second, SQL Server 2000 natively supports (as part of the database core) the FOR XML statement and OpenXML. These features are built into the database, and execute as part of an ordinary SQL query. To answer one of the questions you asked, FOR XML queries return a stream of XML. When viewed in a tool like Query Analyzer or Enterprise Manager, this stream may be displayed as a rowset containing a single column of text chunks, which when concatenated together form the XML.
      Finally, there are features that are part of SQL XML. These include XML Views, updategrams, bulkload, XPath, and also Internet access to SQL Server 2000. These are middle-tier features that are not part of the core database engine. SQL XML is updated regularly on the Web (see http://www.microsoft.com/sql/downloads/default.asp). SQL XML 2 Beta 1 is the most recent release. In it, there is support for XSD schemas and middle-tier FOR XML. SQL XML features can be accessed programmatically through interfaces like ADO/SQLOLEDB, or through the Internet using HTTP.
      In SQL XML, bulkload is implemented as a separate COM object, but the rest of SQL XML is not. Bulkloading XML cannot be performed directly by SQL Server; the operation goes through SQL XML's Bulkload object.

Q In my table, I store the whole XML DOM in a single column, but I need to update an element's value alone. So, if my XML looks like this
<root>
    <element1>123</element1>
    <element2>455</element2>
</root>
      I need to get the value of element2 to be updated with xxx as:
<root>
    <element1>123</element1>
    <element2>xxx</element2>
</root>
A If you store the whole XML as an ntext blob, then you have no option other than replacing the entire document value. You can use annotated schemas to shred the document into relational values. For example, the following document could be represented as an XML schema (only a fragment is shown here):
<element name="root" sql:relation="YourTable">
  <complexType>
    <sequence>
      <element name="element1" sql:field="Column1"/>
      <element name="element2" sql:field="Column2"/>
    </sequence>
  </complexType>
</element>
      Then, in the database you would have one table, YourTable, with two columns, column1 and column2, like this:
Column1    Column2
123            456
      The value could be updated using an updategram against this schema, or using SQL statements directly. Read the XML and Internet sections of SQL Server 2000 Books Online for more information about these XML features.

Q I have a page that has two select boxes. If the user makes a selection from one of the two, I need the other one to be disabled. Also, if they realize that they need to make their selection from the other one, they can undo the disabling. I basically need to dynamically keep them from making a selection out of each select box. Is there a way to do this?

A Yes, you can programmatically disable the other checkboxes when one is selected by setting the disabled property on them to true when the other is selected. See the code in Figure 2 for an example.

Q I am trying to create a performance tool for a customer by sinking the onsubmit and the readystatechange events. However, I have a form which posts to itself where the sink is not working. I am having a problem setting the onsubmit handler for a form. If I make a button where the input type=submit, the handler syncs up. But if I let it remain as an input type button, the handler does not trap the onsubmit event. I'm calling the submit method for the form, but the event handler does not take it (see Figure 3).

A The submit method does not invoke the onsubmit event handler (see http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onsubmit.asp). Call the onsubmit event handler directly. When using Internet Explorer 5.5 and later, you can call the fireEvent method with a value of onsubmit in the sEvent parameter (see http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/fireEvent.asp). The onsubmit handler gets invoked when you submit a form using methods other than script (input type=submit or input type=image). The expectation is that if you are already submitting a form through script, you would also be handling any validation in that same script, or you could call your handler directly from your script. Submitting the form through script does offer greater control, but you will have to call the handler manually.

Q I'm querying SQL Server with FOR XML AUTO to get rows from a database table that holds dates. The XML returned has the dates in the form of "2001-05-14T00:00:00". I can't find any DOM functions to convert that text to a date. Cdate does not like the "T". The only alternative I've been able to find is to pre-convert in the select statement with convert(Char(10),Date,101). I'd rather not do this!

A Well, the solution you choose will depend on the format you want. AUTO mode uses ISO 8601, which is the XML-sanctioned format for date/time strings. There is also CONVERT mode 126 in T-SQL (see the SQL Server Books Online for details). ISO 8601 isn't as human-readable as, say, "Monday, May 15, 2001".
      You can override this conversion on the server by using your own date-to-string conversion. You can also pick out only the date, or only the time part of the string. Or, you can bring down the whole ISO 8601 string to the client, and use XSLT to reformat the date/time information. It's up to you.
      You should note also that the time zone on the database may not be the same as the time zone on the client. Depending on your application, you may need to shift your date/times appropriately before displaying on the client or inserting client data back into the database.
      You could also bring down the whole ISO 8601 string to the client, and use XSLT to reformat the date/time information.
      MSXML 4.0 XSLT has two built-in extension functions that you may find useful: ms:format-date and ms:format-time. The old XSL namespace also had similar built-in functions, although I wouldn't recommend using this language now that there is XSLT support. MSXML 3.0-compliant XSLT doesn't have such functions, although you can write script extension functions instead. A reimplemented version of the Internet Explorer 5.0 XSL formatDate and formatTime functions in JScript can be downloaded from the link at the top of this article. You could also implement these functions as XSLT named templates if interoperability is necessary, although it would be a nasty job. XSLT 2.0 requires formatting dates without extensions.
      There's also the alternative of formatting the Date string in SQL when creating the XML. For example, you can use
"Select OrderID, CustomerID, Convert(char(12), OrderDate, 107)
 from Northwind.Orders for XML Auto" 
which returns:
<Northwind..Orders OrderID="10248" CustomerID="VINET" 
 OrderDate="Jul 04, 1996"/>.
This practice can be much more useful if you want to make sure you always interpret the date correctly across international boundaries. With a full date name, that is not a problem. Moreover, almost all the programming languages understand a full text date.

Got a question? Send questions and comments to webqa@microsoft.com.
Thanks to the following Microsoft developers for their technical expertise: Michael Bayha, Michael Brundage, Srinivasa Burugapalli, Surekha Burugapalli, Jeremy Chapman, Jack Cragoe, Bruno Denuit, Bulent Elmaci, Puneet Gupta, Todd Hibbs, Robert Lin, Anup Manandhar, Jonathan Marsh, Chad McCaffery, Dan Mohr, Hamsa Murugesan, Joel Palmer, James Pinkerton, Dale Rogerson, Peta Searson, Chad Ken Tanner, Drew Thompson, Peter Torr, Adam Vandenberg, Alexander Vaschillo, Juanya Williams.

© 2008 Microsoft Corporation and CMP Media, LLC. All rights reserved; reproduction in part or in whole without permission is prohibited.
Page view tracker