Here is the same content in en-us.
From the July 2001 issue of MSDN Magazine.
|Office Chart Control, Opening Windows in ASP, Getting a Referred URL, and More |
|Edited by Nancy Michell|
|Download the code for this article: WebQA0107.exe (39KB)|
Browse the code for this article at Code Center: Office Chart Control
|Q Can you recommend any sample files or code for creating dynamic charts or graphs from XML data? I'd like them to look like the graphs in Microsoft® Office.|
A The following is a good solution that uses Office Web Components. Look at the two charts in Figure 1. The top one uses Office Web Components that ship with Office XP, and the bottom one uses Office 2000 Web Components. The HTML for the page is shown in Figure 2. To include the chart control from Office XP, use the class ID listed first in Figure 2. To use the chart control from Windows 2000, use the second class ID. The code also alerts the user if Office XP components are not installed.
Figure 1 Using Office Web Components
The data for the charts is taken from chartXP.xml and chartme.xml. The formatting is found in chartXP.xsl. All of these files are available for download from the link at the top of this article.
More information on using XML as an API can be found on the MSDN Online Web Workshop at http://msdn.microsoft.com/xml/articles/xml10162000.asp.
Q I'd like to be able to pop up a small overlay window, allow someone to fill in some database information, and then have the window close. I'm not sure how to create and close the window or if there are any special tricks using ASP code.
A ASP is a server-side scripting environment. Any instance of an opened window would need to run on the client side in the user's browser utilizing client-side scripting (such as VBScript or JScript®). When running VBScript on the server, user interface elements such as msgBox are actually disabled. ASP comes into play here for inserting the form data into your database.
First, create a small JScript function that will launch the popup window and create the form when the Enter Company data link is clicked (see Figure 3). An interesting point to note about the code for this (shown in Figure 4) is that it creates the form dynamically. It is not actually opening an existing page containing the form elements. The HTML and form elements are created within the body of the function. You could expand on this idea to create your form based on the link the user selected.
Figure 3 Popup Window
The LaunchWin function is called by clicking on the link:
After the user has selected an option, the window is launched with a form that presents the user with two textboxes, ready to accept input that will end up in the database (in this case, the classic Northwind database that ships with SQL Server™). When the Submit button is selected, the data is sent to the enterFormData.asp page. The code in Figure 5 belongs at the top of the enterFormData.asp page to extract and enter the form data. In this code, you are simply creating a Recordset object and using ADO to insert the values of your requesting form fields into the database. Then you close the connection and release the object reference from memory.
<a href="#" onClick="LaunchWin()">Enter Company data</a>
Next, use the following logic to close the top layer window when the onLoad event is triggered during page loading.
At this point, the new window containing the form has been opened, the user has entered their information, that information has been inserted into the database, and the opened window has been closed. It is good practice to provide the user with some kind of feedback to inform them that their information has been entered into the database. Figure 3 shows a view of both windows.
Note that this example doesn't contain validation and error detection; you'd need to include these in a production environment.
Q I'm usually able to grab the referring URL sent via a form POST with the following code:
But that fails if I get transferred via something like window.location.href.
Is there a single ASP object that will return the URL regardless of the way you were transferred, or is there a nice technique to pick up the various possible transfers and redirects? Can I always read the header?
A Well, not all cases are actually catchable—not all requests have a referrer header in them. So the real question is whether the client request even had a referrer header in it to begin with. If the request did have a referrer header, then you should be able to get it with that code; if it didn't, then you would never be able to get it.
Some of the MSN® pages employ the method of passing the referrer via a URL such as this:
In the ASP page you can then just use request.querystring("from") to get the value.
It sounds like the problem in your case is that Microsoft Internet Explorer (or WinInet) is deciding not to add the referrer header because it's not coming from an <A HREF> tag. There may be some different client-side code that would result in Internet Explorer sending the referrer header, but for simplicity you may just want to use the solution I just presented.
Q I am looking for a way to add "Export to Microsoft Excel" functionality to one of my Web projects. I would like to take the data from an ADO recordset or a client-side HTML table and export it to an Excel file on the client, so the user can view HTML data and simply click a button to open the data in Excel. The closest thing I have found is piping HTML data (HTML table on a Web page) to a spreadsheet object on a Web page (see Figure 6). The code for this example is in Figure 7.
Figure 6 Excel Spreadsheet
I am looking to export data with one click to the user, so ideally I'd like to create an Excel file on the server, then have it download to the client automatically. But maybe I should have SQL export to a csv file, then e-mail it to the user.
A If you upgrade to version 10 of the spreadsheet control, you can query data directly into the control. The user then has Export to Microsoft Excel capabilities right there.
If upgrading is not possible, then you could use the version 9 Pivot Control. It can connect to data and has detail or recordset viewing and an Export to Microsoft Excel option. However, with the Pivot Control Export to Microsoft Excel you get a PivotTable® in Excel.
Instead of exporting to Excel, a good option is to have the user get the data from within Excel. A simple sheet containing a macro can get the data from a Web page in XML format and then inject it into the sheet. Since you probably want this functionality only on specific pages that report data, this is a clean option that respects the security settings at both ends (client and server).
Create a csv file on the Web vroot, configure the Internet Information Services (IIS) vroot to process .csv extensions with the ASP engine, then in the local csv file put a little ASP code that generates a comma-delimited list of all the columns you want to export. Put the following at the bottom:
This tells Internet Explorer to download the file (which is a .csv file that can be opened by Excel) and the user can choose to download it or open it. So far it works quite nicely.
Response.ContentType = "application/msexcel"
Also check out Andrew Clinick's article at http://msdn.microsoft.com/workshop/languages/clinic/scripting10162000.asp, which describes how to get ASP pages to generate Office content.
Q I use window.open to load a Web page that takes in a comma-delimited list of IDs. This works great if I pass in a few dozen. But once I go over roughly 700 IDs on the URL (approximately 4000 bytes of data), the list just gets cut off.
How many bytes can a single URL be under Internet Explorer 5.01? How many bytes can you POST to a form in another window? What's the maximum number of bytes you can pass in as a window argument with window.open? Are there any other ways to pass data from one window to another?
A You may be running into limits with IIS as well as the limits for POST. IIS 5.0 has a limit of 128KB for the HTTP request (before the entity body), which is much smaller than the 2MB limit of IIS 4.0. This can be set via the MaxClientRequestBuffer setting in the registry (see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q260694).
You can run into a 4096-byte limit for a URL and window parameter. If you use the POST you shouldn't run into any limit.
If you're opening the new window with window.open, (and if the information you're passing to the page does not have to go to the server), why pass it as GET or POST at all? Why not just do the following on the client in the page being opened?
var w = window.opener;
myData = w.SomeFunctionDefinedOnMainPage();
Q I am trying to add a dropshadow effect to some of the text in my Web pages, but when I try using the TEXT-SHADOW attribute in my stylesheet file, nothing happens. Could you please show me how this should look?
A You can use DropShadow filter to achieve the result you're looking for. Figure 8 shows the effect.
Figure 8 The DropShadow Effect
Figure 9 shows how to use the DropShadow filter. If you have any further questions, check out the dropshadow reference at http://msdn.microsoft.com/workshop/author/filter/reference/filters/dropShadow.asp.
| Thanks to the following Microsoft developers for their technical expertise: Tim Aranki, Pete Baxter, Dean Bell, Smitha Bhat, Daniel Boerner, Stephane Bouillon, Mike Christensen, Andrew Clinick, Zeb DeMeerleer, Rick Engle, John Frum, Geoff Gray, Deepak Gulati, Michael Kaplan, Andy Macourek, Jeremy Phelps, Dan Ricker.|