Computer Books Online Computer Books Online Computer Books Online Computer Books Online
 
Computer Books Online
HomeSite Map
Site Map
Computer Books Online Home Search Browse Used Books Customer Service Computer Books Online  
My Order View Cart Check Out Contact Us
Find Books
Find Books Find Books
Find Books
Advanced Search Advanced Search
Advanced Search
Categories Categories
Categories
Coming Soon Coming Soon
Coming Soon
On Sale On Sale
On Sale
Used Books Slightly Worn
Used Books
New Releases New Releases
New Releases
Content Content
Content
Chapters Articles
Chapters
Blog Blog
Chapters
Chapters Chapters
Chapters
Contest Contest
Contest
Free Computer Mags Free Computer Mags
Free Computer Mags
Laugh Laugh
Laugh
Tips Tips
Tips
Mailing List Join Our Mailing List
Mailing List

Your Email Your Email:
Your Email
Subscribe Subscribe
Update Update
Remove Remove

Join Mailing List

Sample Newsletter About Mailing Lists
Company Information
Company Information Company
Computer Books Online
Contact Us Contact Us
Contact Us
Customer Service Customer Service
Customer Service
Policies and Procedures Policies and Procedures
Policies and Procedures
Privacy and Security Privacy and Security
Privacy and Security
International International
International
Computer Books Online

 

 
Tips Categories Active Server Pages
 
 

Search All Active Server Pages Tips:  



Page 1 of 10
 
[ 1 2 3 4 5 6 7 8 9 10 ]

            Why relative filespecs may not work in ASP

            Use ADO's native OLEDB drivers instead of ODBC

            Quickly determine client browser types in JavaScript code

            Generate accurate ADO RecordCount values in ASP

            Use a single ADO connection to reduce ASP server load

            Register WSC scripts before using them in ASP

            Obtain a header list with ASP's ServerVariables collection

            Create Visual InterDev 6.0 ASP code templates

            A caveat when using ASP's Response.Redirect method

            Simplify loading stored values via ASP

            Convert ADO fields to XML tags without errors

            Syntax requirements for integrating XSL into ASP and HTML

            Configure IIS from DOS in Windows 2000

            Cumulative patches for IIS 4.0/5.0/5.1 released at Microsoft

            How to determine which version of the .NET Framework you're running

 Why relative filespecs may not work in ASP


Even though the helpfile states you can use relative directory paths with FileSystemObject objects, you probably encountered an error if you tried to use them in an ASP path. That's because the directory that contains the ASP page doesn't become the current directory, as far as the FileSystemObject is concerned. To illustrate, run the following VBScript code in an ASP page:



<%

Set FileObject = Server.CreateObject
("Scripting.FileSystemObject")

filespec="\test.jpg"

CurrDir = FileObject.GetAbsolutePathName(".")

response.write "Using CurrDir: " & CurrDir & filespec & "<br>"

if FileObject.FileExists(filespec) then

  response.write "[CurrDir] File Found<br>"

else

  response.write "[CurrDir] No File found<br>"

end if


response.write "Using MapPath: " & Server.MapPath(filespec) & "<BR>"

if FileObject.FileExists(Server.MapPath(filespec)) then

  response.write "[MapPath] File Found<br>"

else

  response.write "[MapPath] No File found<br>"

end if



Set FileObject = Nothing

%>



Submitted by: Michael Harris

UP



 Use ADO's native OLEDB drivers instead of ODBC


When you create an connection string, ADO gives you a choice
between indicating a data source driver as either a Driver, as in


Driver={SQL Server};DBQ=database_file



or a Provider, such as


Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database_name


However, when you use the first option, ADO uses older ODBC drivers to connect to the data source; whereas the second form uses OLEDB, which is ADO's native data access interface. For this reason, you should use the Provider option whenever possible. Such native OLEDB drivers exist for SQL Server, Index Server, Site Server Search, and
Oracle, among others.


UP



 Quickly determine client browser types in JavaScript code


The document object model and ASP pages offer several ways to determine a client's browser type. Most, however involve long parsing routines that search for specific substrings within a larger string. Fortunately, using JavaScript, there's a quick way to determine if the client browser is either Netscape Navigator 4+ or Internet Explorer 4+. The basic idea is that you test for objects in the browser's DOM that don't exist in the other browser's
DOM. For example, IE 4.0 + browsers include the document.all collection, while NN4.0 + browsers support the document.layers collection. If one of these objects is null, then your code can infer that the client is the other browser type. For example, the following script displays the boolean results of each test when you load a Web page:


<script language="JavaScript">


var nav4 = !(document.layers == null)

var iex4 = !(document.all == null)



alert("Nav: " + nav4 + " IE4: " + iex4)

</script>



As you can see, the first expression sets the nav4 variable equal to the opposite of document.layers==null. So, if you view this page in an IE 4+ browser, document.layers is null, and the entire expression evaluates to false.

UP



 Generate accurate ADO RecordCount values in ASP


As you know, the ADO RecordCount property returns the number of records in an ADO recordset. Of course, in several instances, this property also returns a -1 instead. The value RecordCount returns depends on the recordset's cursor type: -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.


You may be surprised to learn that RecordCount will be -1 for recordsets created with the Execute method from a Connection or Command object. That's because this method generates a forward-only recordset, which, as we mentioned earlier, returns -1.



As an example, enter and run the following procedure in a
standard ASP page. When you open it, the page displays -1
for the recordset based on myConRst, and 6246 for myKeyRst.


<%

Dim myConn, myComm, myConRst, myKeyRst

Dim sConnection

sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

   "Data Source=D:\Microsoft Visual Studio\VB98\Biblio.mdb"


Set myConn = Server.CreateObject("ADODB.Connection")

Set myKeyRst = Server.CreateObject("ADODB.Recordset")


myConn.Open sConnection

myComm = "Select * From Authors"

Set myConRst = myConn.Execute(myComm, , 1)



myKeyRst.Open myComm, myConn, 1

%>



RecCount <BR>

>From Connection: <%=myConRst.RecordCount%><BR>

>From Recordset: <%=myKeyRst.RecordCount%>



<%

Set myKeyRst = Nothing

Set myConRst = Nothing

Set myConn = Nothing

%>

UP



 Use a single ADO connection to reduce ASP server load


If you need to execute multiple SQL statements on a single database in a single ASP page, it's often wise to open a single Connection and reuse it multiple times. Doing so reduces the number of times the server must open and close the same database, which can significantly increase the server's load. To use a single connection, create the
database Connection at the beginning of the page, then destroy it at the end. When you Execute a SQL statement, whether it returns a Recordset or not, specify the active Connection. Here's an example:



<%

strDSN = "DSN=database;UID=username;PWD=password"



Set conn = Server.CreateObject("ADODB.Connection")

conn.Open strDSN



strSQL = "select column from table"



Set rsResults=conn.Execute(strSQL, , 1)



if not rsResults.eof then

       temp = rsResults("column")

else

        temp = "No Results"

end if



'close the Recordset, but leave the Connection open

rsResults.Close



strSQL = "delete from table where column=123"

conn.Execute strSQL, , 1



'Done executing SQL statements at this point, so close the Connection.

conn.Close



set rsResults = Nothing

set conn = Nothing

%>



Submitted by: Brian Coverstone [brian@pcioh.com]


UP



 Register WSC scripts before using them in ASP


The Windows Scripting Component is a great tool that let's you
create COM components for use in ASP pages. What's more, you can
use either VBScript or JavaScript to give them functionality. When
you create a WSC component, however, you must register it before
you can use it in an ASP page. To do so, open Windows Explorer and
right-click on the WSC file you just created. Select Register from
the shortcut menu. To create an object variable based on the
new script object, use code similar to


Set objXMLCreate = Server.CreateObject("MyScriptObj.WSC")


At this point, you're free to access any of the object's methods
and properties.

UP



 Obtain a header list with ASP's ServerVariables collection


The SeverVariables collection contains all kinds of information about the calling client and the server. For instance, you can determine a visitor's browser type with the HTTP_USER_AGENT variable. Or, you can use HTTP_REFERER to determine the referring Internet address. Not all browsers support the same headers, however. To see a quick list of the headers supported within a browser, run the following code.


<HTML>

<BODY>

<TABLE BORDER=1>

<TH COLSPAN=2>ServerVariables</TH>

<%

For Each var in Request.ServerVariables

  With Response


    .Write("<TR>")


    .Write("<
TD><B>" & var & "</B>
:</TD>")


    .Write("<TD>") & Request.ServerVariables(var) _

      & "</TD>")

    .Write("</TR>")

  End With

Next

%>

</TABLE>

</BODY>

</HTML>

UP



 Create Visual InterDev 6.0 ASP code templates


Instead of retyping the same code lines on virtually every ASP
page that you create in Visual InterDev 6.0, simply open
Program Files | Microsoft Visual Studio | VIntDev98 | Templates |
Web Project Items | New ASP Page.asp file, and then enter the
code that you want duplicated, i.e. included files, titles,
metatags. Save your work, and any new ASP page that you create
will contain the new code.


Submitted by: Will Smith
[will@newtweb.com]

UP



 A caveat when using ASP's Response.Redirect method


When ASP encounters the Response or End methods, it immediately halts script execution in both the GLOBAL.ASA file and in the application page. As a result, ASP won't execute any script that follows the Redirect method. Instead, it either ends the session or begins processing the new page. For this reason, you should always make the Redirect method the last call in any script.

UP



 Simplify loading stored values via ASP


When loading an <OPTIONS> list from a database table, it's much
easier to call a procedure that uses process parameters. This way,
you can use the same procedure for several different operations. For
example, suppose you want to fill a Listbox with a list of animals.
In addition, you've set up several checkboxes on a Web page that let
the user simply view the list, or load the list with one of the
animals already selected. The following example shows how you might
process the resulting page. (To save space, we hard-coded the two
parameters.)



<!-- #include File="DBConnect.Asp" -->

<HTML>

<BODY>

<FORM>

<SELECT name=Atype size= 5>



<%

Dim chkMode

chkMode = 2 'or Request.Form("chkMode")

fillOptionList chkMode,"Snake"

%>

</SELECT>



<%

Sub fillOptionList(myMode, optionValue)



Dim rsAnimal

Dim strSelected



set rsAnimal = CreateObject("ADODB.recordset")

With rsAnimal

     .Open "tblAnimals", strDB, adOpenStatic,,adCmdTable




    Do While Not .EOF

       Select Case myMode

          Case 1

            strSelected = ""

          Case Else

            If optionValue = rsAnimal("Animal") Then

              strSelected = " SELECTED"

            Else

              strSelected = ""

            End if

       End Select


        Response.Write("<OPTION" & strSelected & " VALUE=" _

          & rsAnimal("ID") & ">" & rsAnimal("Animal") & "</OPTION>")

        .MoveNext

         Loop



      .Close

End With

Set rsAnimal = Nothing

End Sub



%>



</BODY>

</HTML>



For the OPTION elements, this code produces output HTML like this:

<SELECT name=Atype size= 5>



<OPTION Value=1>Cat</OPTION>

<OPTION Value=2>Cow</OPTION>

<OPTION Value=3>Dog</OPTION>

<OPTION SELECTED Value=4>Snake</OPTION>

<OPTION Value=5>Elephant</OPTION>

<OPTION Value=6>Fish</OPTION>



</SELECT>



Submitted by: Faisal Ladak

[fladak@systech-inc.net]

UP



 Convert ADO fields to XML tags without errors


XML tag names can't contain several special characters or spaces. Therefore, when you use ADO field names as XML tags, make sure to rename the fields, if necessary, in the SQL statement. For example, if you use the following SQL statement:


Select [Employ ID], Name FROM Employees


and then use XMLDOM to convert the recordset fields into XML, the XML document will generate an error. That's because XMLDOM's creation methods convert the [Employ ID] fieldname into <Employ ID>. However, the space is an invalid character. To avoid this error, use an alias name in the SQL string, such as:


Select [Employ ID] AS EmployID, Name FROM Employees


UP



 Syntax requirements for integrating XSL into ASP and HTML


Since an XSL stylesheet is an XML document itself, its markup must
conform to XML grammar rules. Most notably, you must ensure that
you close all tags. Since HTML is considerably more forgiving in
this regard, make sure that the markup in XSL sheets will
successfully parse. For example, to use <BR> to express a line
break, you must enter <BR> instead. To read more about the
W3's recommendation for XHTML, which addresses this issue, see
http://www.w3.org/TR/xhtml1/

UP



 Configure IIS from DOS in Windows 2000


Windows 2000 provides a wealth of IIS management and administrative scripts that you can use from the DOS command prompt. Among other things, you can search your Web server for a virtual Web site, display a tree of the structure of your IIS server, create Web sites and virtual directories, start and stop services, and more. Take a look at the following URL for more information:

http://support.microsoft.com/view/tn.asp?kb=308622

UP



 Cumulative patches for IIS 4.0/5.0/5.1 released at Microsoft


As you know, keeping your Web server up-to-date with the latest patches and security fixes can be a real challenge. Fortunately, Microsoft recently released a cumulative patch that saves you a lot of trouble. For IIS 4.0, the patch includes all fixes released since Windows NT 4.0 Service Pack 6a. For IIS 5.0 and 5.1, the patch includes all fixes released to date. Period. Navigate to the following URL to download and install this critical product update:

www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/MS02-018.asp

UP



 How to determine which version of the .NET Framework you're running


Since the .NET Framework itself is just a collection of classes and structures, you might wonder where to look to determine the exact version, including installed service packs, of the Framework you've got. This is especially true when you inherit responsibility for a machine running .NET. Here's where to look:

For Windows 2000 and XP, you need to run the .NET Framework Configuration MMC snap-in. On Windows XP, this is tucked away under Administrative Tools on the Start menu. For Windows 2000, you'll have to manually add it to a running instance of MMC. In either case, choose Help | About from the snap-in menu, and you'll see which version you've got to work with.

For Windows 98, Me, and NT 4.0, you'll need to download this snap-in from Microsoft, since it isn't installed by default. Get it at http://download.microsoft.com/download/platformsdk/Install/1.2.0/W9XNT4Me/EN-US/IMMC.EXE.

UP





Page 1 of 10
 
[ 1 2 3 4 5 6 7 8 9 10 ]

 

Free Computer and Technical Magazines!

 

 

 

 

Search I Book Index I Contact I Feedback
Copyright © 1997-2013 Computer Books Online
About Us I Publishers & Authors I Privacy Policy
All products and company names mentioned herein are the trademarks of their respective owners. No part of this website may be reproduced without the prior written permission of Computer Books Online. Prices and availability subject to change without notice.
This website may contain affiliate links and/or sponsered links.