The VB code produces HTML that displays the following TABLE record data:
We''''ll get the titles from the database using the GetRows() method, which conveniently stores our record fields in a multidimensional array. In order to identify which title the user selects, a query string will be attached to the end of each hyperlinked title within the HTML code. This query string will use the titles'''' NoteID database field value, which is unique for each title.
Here''''s an example of how the title HTML <A> tags are structured within the TABLE TD tags sent back from our VB code to an ASP file, which we''''ll name NoteExample.asp. Notice that the user must have selected the "Buffering" title since <A> tags don''''t enclose it. The VB code will send back the <TD></TD> tags along with the tags'''' content. We''''ll also provide <FONT></FONT> tags, even though the <A> tag will override the font title colors. We can use this to our advantage and set the FONT COLOR property value to a different color than the page''''s BODY LINK value so that the selected title will display a different color than the linked titles. Remember, our VB code will omit the <A></A> tags for the title that is selected by the user, thereby using the FONT tag color parameter rather than the BODY LINK color parameter.
<TD WIDTH="74" NOWRAP VALIGN="top">
<FONT FACE="Verdana" SIZE="1" COLOR="GRAY">
<A HREF="NoteExample.asp?ID=1">Intro</A><BR>
<A HREF="NoteExample.asp?ID=2">Style Tables</A><BR>
<A HREF="NoteExample.asp?ID=3">GetRows()</A><BR>
Buffering<BR>
<A HREF="NoteExample.asp?ID=5">Transactions</A><BR>
</FONT>
</TD>
The URL for each title will send the user back to the current ASP file being displayed -- basically having the ASP file call itself when one of the titles is selected. The VB code will also assign a query string named "ID" to the end of each titles'''' URL within the <A> tag. The value of the ID query string will match each title''''s unique database record NoteID value. Every time our example NoteExample.asp file is called with an ID query string attached to the end of its URL, we''''ll send the ID query strings value to the VB code as a method parameter value so that the VB code will know which title was selected. So whether a URL with an ID query string is called from within the ASP file, or from another Internet link, the VB code will display the text of the title whose NoteID equals the ID query string value.
Below is the line of ASP code that will precede the call to the VB method and assign the "ID" query string variable value to a local ASP file variable. Basically, this line of code sets the local ASP variable named aspNoteID to the NoteID value of the title that the user selected. We''''ll then use the aspNoteID variable as a VB method parameter to let the VB method code know which notes'''' title text to display. If the NoteExample.asp file is called without a query string named ID, then the following line of ASP code will set the aspNoteID to the default of 1. Sending the VB method code a parameter value that is less than 1, or greater than the number of titles in the database table, would cause an error.
aspNoteID = Request.QueryString("ID")
The right side of our HTML TABLE record data area will be simpler than the left-hand side. It basically will contain our selected titles'''' text enclosed in HTML TD and FONT tags.
If aspNoteID < 1 Then aspNoteID = 1
Since the VB method will return data within two sets of<TD></TD> tags, we''''ll need to provide the <TABLE></TABLE> and <TR></TR> tags from within the ASP file that calls the VB method. Although these tags could also be constructed within the VB method, I have found that leaving them in the ASP file allows the end developer greater freedom to change the structure and appearance of the table, while still allowing the VB code to iterate through the database information.
<TD WIDTH="124" VALIGN="top" BGCOLOR="#EFEFEF">
<FONT FACE="Verdana" SIZE="1" COLOR="NAVY">
This is an example application written for an article on server-side VB programming
</FONT>
</TD>
This, again, is a balancing of where to draw the line between presentation and business code. On one extreme, you could construct the entire ASP page''''s HTML code in the VB code, which would consist of all the code enclosed in, and including, the <HTML></HTML> tags. Other programmers would prefer to construct all the <A> tags, title values, title text, <FONT> tags, <TD> tags, etc., in the ASP file itself and just send back a recordset, or an array, from the VB code filled with the title names and selected title text. (See articles "How To Pass a RecordSet From a VB Component to an asp File" and "How To Pass a Variant Array Populated with a RecordSet From a VB Component to an asp File" at http://www.dougdean.com for more information on these alternatives). I have found sending back database field values within <TABLE> or <TD> tags is the best compromise that balances issues like maintenance, speed, source code security, etc.
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




