Here is the same content in en-us.
From the August 2001 issue of 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 |
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.
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
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.
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.
codebase="http://<% =Request.ServerVariables("SERVER_NAME") %>/cabs/
height=0 width=0 VIEWASTEXT>
A You should try the following code, replacing oControl with your OBJECT ID.
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.
if ("undefined" != typeof(document.all("oControl")) &&
null != document.all("oControl").object)
// The control is installed
// The control is not installed
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?
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:
<meta http-equiv="redirect" content="10; URL=#bottom">
Make sure you remember to put the anchor at the bottom of the page where you want the link to jump to, like this:
window.onload = function()
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:
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."
<form name="form1" onsubmit="return ValidateForm(this);">
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
I need to get the value of element2 to be updated with xxx as:
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):
Then, in the database you would have one table, YourTable, with two columns, column1 and column2, like this:
<element name="root" sql:relation="YourTable">
<element name="element1" sql:field="Column1"/>
<element name="element2" sql:field="Column2"/>
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"
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.
<Northwind..Orders OrderID="10248" CustomerID="VINET"
OrderDate="Jul 04, 1996"/>.
Got a question? Send questions and comments to firstname.lastname@example.org.
| 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.|