You are on page 1of 21

Example 43 :Send extra information within a link <html> <body> <a href="demo_simplequerystring.asp?color=green">Example</a> <% Response.Write(Request.

QueryString) %> </body> </html> Example 44 :A QueryString collection in its simplest use <html> <body> <form action="demo_simplereqquery.asp" method="get"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <input type="submit" value="Submit"> </form> <% Response.Write(Request.QueryString) %> </body> </html> Example 45 :How to use information from forms <html> <body> <form action="demo_reqquery.asp" method="get"> Your name: <input type="text" name="fname" size="20" /> <input type="submit" value="Submit" /> </form> <% dim fname fname=Request.QueryString("fname") If fname<>"" Then Response.Write("Hello " & fname & "!<br />") Response.Write("How are you today?") End If %>

</body> </html> Example 46 :More information from a form <html> <body> <% If Request.QueryString<>"" Then If Request.QueryString("name")<>", " Then name1=Request.QueryString("name")(1) name2=Request.QueryString("name")(2) end if end if %> <form action="demo_reqquery2.asp" method="get"> First name: <input type="text" name="name" value="<%=name1%>" /> <br /> Last name: <input type="text" name="name" value="<%=name2%>" /> <br /> <input type="submit" value="Submit" /> </form> <hr> <% If Request.QueryString<>"" Then Response.Write("<p>") Response.Write("The information received from the form was:") Response.Write("</p><p>") Response.Write("name=" & Request.QueryString("name")) Response.Write("</p><p>") Response.Write("The name property's count is: ") Response.Write(Request.QueryString("name").Count) Response.Write("</p><p>") Response.Write("First name=" & name1) Response.Write("</p><p>") Response.Write("Last name=" & name2) Response.Write("</p>") end if %> </body> </html> Example 47 :A form collection in its simplest use

<html> <body> <form action="demo_simpleform1.asp" method="post"> First name: <input type="text" name="fname" value="Donald" /> <br /> Last name: <input type="text" name="lname" value="Duck" /> <br /> <input type="submit" value="Submit" /> </form> <% Response.Write(Request.Form) %> </body> </html> Example 48 :How to use information from forms <html> <body> <form action="demo_simpleform.asp" method="post"> Your name: <input type="text" name="fname" size="20" /> <input type="submit" value="Submit" /> </form> <% dim fname fname=Request.Form("fname") If fname<>"" Then Response.Write("Hello " & fname & "!<br />") Response.Write("How are you today?") End If %> </body> </html> Example 49 :More information from a form <html> <body> <form action="demo_form2.asp" method="post"> First name: <input type="text" name="name" value="Donald" /> <br /> Last name:

<input type="text" name="name" value="Duck" /> <br /> <input type="submit" value="Submit" /> </form> <hr /> <p>The information received from the form above was:</p> <% If Request.Form("name")<>"" Then Response.Write("<p>") Response.Write("name=" & Request.Form("name")) Response.Write("</p><p>") Response.Write("The name property's count is: ") Response.Write(Request.Form("name").Count) Response.Write("</p><p>") Response.Write("First name=" & Request.Form("name")(1)) Response.Write("</p><p>") Response.Write("Last name=" & Request.Form("name")(2)) Response.Write("</p>") End if %> </body> </html> Example 50 :A form with radio buttons <html> <% dim cars cars=Request.Form("cars") %> <body> <form action="demo_radiob.asp" method="post"> <p>Please select your favorite car:</p> <input type="radio" name="cars" <%if cars="Volvo" then Response.Write("checked")%> value="Volvo">Volvo</input> <br /> <input type="radio" name="cars" <%if cars="Saab" then Response.Write("checked")%> value="Saab">Saab</input> <br /> <input type="radio" name="cars" <%if cars="BMW" then Response.Write("checked")%> value="BMW">BMW</input> <br /><br /> <input type="submit" value="Submit" /> </form> <%

if cars<>"" then Response.Write("<p>Your favorite car is: " & cars & "</p>") end if %> </body> </html> Example 51 :A form with checkboxes <html> <body> <% fruits=Request.Form("fruits") %> <form action="demo_checkboxes.asp" method="post"> <p>Which of these fruits do you prefer:</p> <input type="checkbox" name="fruits" value="Apples" <%if instr(fruits,"Apple") then Response.Write("checked")%>> Apple <br> <input type="checkbox" name="fruits" value="Oranges" <%if instr(fruits,"Oranges") then Response.Write("checked")%>> Orange <br> <input type="checkbox" name="fruits" value="Bananas" <%if instr(fruits,"Banana") then Response.Write("checked")%>> Banana <br> <input type="submit" value="Submit"> </form> <% if fruits<>"" then%> <p>You like: <%Response.Write(fruits)%></p> <%end if %> </body> </html> Example 52 :How to find the visitors' browser type, IP address and more <html> <body> <p> <b>You are browsing this site with:</b> <%Response.Write(Request.ServerVariables("http_user_agent"))%> </p> <p>

<b>Your IP address is:</b> <%Response.Write(Request.ServerVariables("remote_addr"))%> </p> <p> <b>The DNS lookup of the IP address is:</b> <%Response.Write(Request.ServerVariables("remote_host"))%> </p> <p> <b>The method used to call the page:</b> <%Response.Write(Request.ServerVariables("request_method"))%> </p> <p> <b>The server's domain name:</b> <%Response.Write(Request.ServerVariables("server_name"))%> </p> <p> <b>The server's port:</b> <%Response.Write(Request.ServerVariables("server_port"))%> </p> <p> <b>The server's software:</b> <%Response.Write(Request.ServerVariables("server_software"))%> </p> </body> </html> Example 53 :List all servervariables you can ask for <html> <body> <p> All possible server variables: </p> <% For Each Item in Request.ServerVariables Response.Write(Item & "<br />") Next %> </body> </html> Example 54 :Welcome cookie <% dim numvisits response.cookies("NumVisits").Expires=date+365 numvisits=request.cookies("NumVisits")

if numvisits="" then response.cookies("NumVisits")=1 response.write("Welcome! This is the first time you are visiting this Web page.") else response.cookies("NumVisits")=numvisits+1 response.write("You have visited this ") response.write("Web page " & numvisits) if numvisits=1 then response.write " time before!" else response.write " times before!" end if end if %> <html> <body> </body> </html> Example 55 :Total number of bytes the user sent <html> <body> <form action="demo_totalbytes.asp" method="post"> Please type something: <input type="text" name="txt"><br><br> <input type="submit" value="Submit"> </form> <% If Request.Form("txt")<>"" Then Response.Write("You submitted: ") Response.Write(Request.Form) Response.Write("<br><br>") Response.Write("Total bytes: ") Response.Write(Request.Totalbytes) End If %> </body> </html> Session Object Example 56 :Return session id number for a user <html> <body>

<% Response.Write(Session.SessionID) %> </body> </html> Example 57 :Get a session's timeout <html> <body> <% response.write("<p>") response.write("Default Timeout is: " & Session.Timeout & " minutes.") response.write("</p>") Session.Timeout=30 response.write("<p>") response.write("Timeout is now: " & Session.Timeout & " minutes.") response.write("</p>") %> </body> </html> Server Object Example 58 :When was a file last modified? <html> <body> <% Set fs = Server.CreateObject("Scripting.FileSystemObject") Set rs = fs.GetFile(Server.MapPath("demo_lastmodified.asp")) modified = rs.DateLastModified %> This file was last modified on: <%response.write(modified) Set rs = Nothing Set fs = Nothing %> </body> </html>

Example 59 :Open a textfile for reading <html> <body> <% Set FS = Server.CreateObject("Scripting.FileSystemObject") Set RS = FS.OpenTextFile(Server.MapPath("text") & "\TextFile.txt",1) While not rs.AtEndOfStream Response.Write RS.ReadLine Response.Write("<br />") Wend %> <p> <a href="text/textfile.txt"><img border="0" src="/images/btn_view_text.gif"></a> </p> </body> </html> Example 60 :Home made hit counter <% Set FS=Server.CreateObject("Scripting.FileSystemObject") Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 1, False) fcount=RS.ReadLine RS.Close fcount=fcount+1 'This code is disabled due to the write access security on our server: 'Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 2, False) 'RS.Write fcount 'RS.Close Set RS=Nothing Set FS=Nothing %> <html> <body> <p> This page has been visited <%=fcount%> times. </p> </body> </html>

FileSystem Object Example 61 :Does a specified file exist? <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") If (fs.FileExists("c:\winnt\cursors\3dgarro.cur"))=true Then Response.Write("File c:\winnt\cursors\3dgarro.cur exists.") Else Response.Write("File c:\winnt\cursors\3dgarro.cur does not exist.") End If set fs=nothing %> </body> </html> Example 62 :Does a specified folder exist? <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") If fs.FolderExists("c:\temp") = true Then Response.Write("Folder c:\temp exists.") Else Response.Write("Folder c:\temp does not exist.") End If set fs=nothing %> </body> </html> Example 63 :Does a specified drive exist? <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") if fs.driveexists("c:") = true then Response.Write("Drive c: exists.") Else

Response.Write("Drive c: does not exist.") End If Response.write("<br>") if fs.driveexists("g:") = true then Response.Write("Drive g: exists.") Else Response.Write("Drive g: does not exist.") End If set fs=nothing %> </body> </html> Example 64 :Get the name of a specified drive <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") p=fs.GetDriveName("c:\winnt\cursors\3dgarro.cur") Response.Write("The drive name is: " & p) set fs=nothing %> </body> </html> Example 65 :Get the name of the parent folder of a specified path <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") p=fs.GetParentFolderName("c:\winnt\cursors\3dgarro.cur") Response.Write("The parent folder name of c:\winnt\cursors\3dgarro.cur is: " & p) set fs=nothing %> </body> </html>

Example 66 :Get the file extension <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Response.Write("The file extension of the file 3dgarro is: ") Response.Write(fs.GetExtensionName("c:\winnt\cursors\3dgarro.cur")) set fs=nothing %> </body> </html> Example 67 :Get the base name of a file or folder <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Response.Write(fs.GetBaseName("c:\winnt\cursors\3dgarro.cur")) Response.Write("<br />") Response.Write(fs.GetBaseName("c:\winnt\cursors\")) Response.Write("<br />") Response.Write(fs.GetBaseName("c:\winnt\")) set fs=nothing %> </body> </html> TextStream Object Example 68 :Read textfile <html> <body> <p>This is the text in the text file:</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) Response.Write(f.ReadAll) f.Close

Set f=Nothing Set fs=Nothing %> </body> </html> Example 69 :Read only a part of a textfile <html> <body> <p>This is the first five characters from the text file:</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) Response.Write(f.Read(5)) f.Close Set f=Nothing Set fs=Nothing %> </body> </html> Example 70 :Read one line of a textfile <html> <body> <p>This is the first line of the text file:</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) Response.Write(f.ReadLine) f.Close Set f=Nothing Set fs=Nothing %> </body> </html> Example 71 :Read all lines from a textfile <html> <body>

<p>This is all the lines in the text file:</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) do while f.AtEndOfStream = false Response.Write(f.ReadLine) Response.Write("<br>") loop f.Close Set f=Nothing Set fs=Nothing %> </body> </html> Example 72 :Skip a part of a textfile <html> <body> <p>The first four characters in the text file are skipped:</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) f.Skip(4) Response.Write(f.ReadAll) f.Close Set f=Nothing Set fs=Nothing %> </body> </html> Example 73 :Skip a line of a textfile <html> <body> <p>The first line in the text file is skipped:</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) f.SkipLine

Response.Write(f.ReadAll) f.Close Set f=Nothing Set fs=Nothing %> </body> </html> Example 74 :Return current line-number in a text file <html> <body> <p>This is all the lines in the text file (with line numbers):</p> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) do while f.AtEndOfStream = false Response.Write("Line:" & f.Line & " ") Response.Write(f.ReadLine) Response.Write("<br>") loop f.Close Set f=Nothing Set fs=Nothing %> </body> </html> Example 75 :Get column number of the current character in a text file <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1) Response.Write(f.Read(2)) Response.Write("<p>The cursor is now standing in position " & f.Column & " in the text file.</p>") f.Close Set f=Nothing Set fs=Nothing %>

</body> </html> AdRotator Example 76 :Display a different image each time a user visits a page <html> <body> <% set adrotator=Server.CreateObject("MSWC.AdRotator") adrotator.Border="2" Response.Write(adrotator.GetAdvertisement("text/advertisements.txt")) %> <p> NOTE: Because images are changed randomly, and because this page has few images to choose from, it will often display the same advertisement twice in a row. </p> <p> <a href="text/advertisements.txt"> <img border="0" src="/images/btn_view_text.gif"> </a> </p> </body> </html> Example 77 :Display a different image each time a user visits a page + the images are links <% url=Request.QueryString("url") If url<>"" then Response.Redirect(url) %> <html> <body> <% set adrotator=Server.CreateObject("MSWC.AdRotator") adrotator.TargetFrame="target='_blank'" response.write(adrotator.GetAdvertisement("text/advertisements2.txt")) %> <p> NOTE: Because images are changed randomly, and because this page has few images

to choose from, it will often display the same advertisement twice in a row. </p> <p> <a href="text/advertisements2.txt"> <img border="0" src="/images/btn_view_text.gif"></a> </p> </body> </html> ----------------------------------------------------------------REDIRECT demo_adrotator2.asp * /banners/rd_htmlref.jpg http://www.w3schools.com/html/html_reference.asp Complete HTML 4.0 Reference 20 /banners/w3schools.gif http://www.w3schools.com Web Tutorials from W3Schools 20 /banners/rd_xhtml.jpg http://www.w3schools.com/xhtml/default.asp XHTML Tutorial 20 ------------------------------------------------------------------Browser Capabilities Example 78 :Find the type, capabilities, and version of each browser that visits your site <html> <body> <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %> <table border="1" width="65%"> <tr> <td width="52%">Client OS</td> <td width="48%"><%=MyBrow.platform%></td> </tr> <tr> <td >Web Browser</td> <td ><%=MyBrow.browser%></td> </tr> <tr> <td>Browser version</td> <td><%=MyBrow.version%></td> </tr> <tr>

<td>Frame support?</td> <td><%=MyBrow.frames%></td> </tr> <tr> <td>Table support?</td> <td><%=MyBrow.tables%></td> </tr> <tr> <td>Sound support?</td> <td><%=MyBrow.backgroundsounds%></td> </tr> <tr> <td>Cookies support?</td> <td><%=MyBrow.cookies%></td> </tr> <tr> <td>VBScript support?</td> <td><%=MyBrow.vbscript%></td> </tr> <tr> <td>JavaScript support?</td> <td><%=MyBrow.javascript%></td> </tr> </table> </body> </html> Example 79 :ContentRotator Display a different content each time a user visits a page (ASP 3.0) <html> <body> <p><b>Note:</b> This example won't work because ASP 3.0 is not installed on our server. </p> <p> <a href="demo_textads.asp"><img border="0" src="/images/btn_view_text.gif"></a> </p> <% set cr=server.createobject("MSWC.ContentRotator") response.write(cr.ChooseContent("text/textads.txt")) %> <p> NOTE: Because the content strings are changed randomly in the text file, and this page has only four content strings to choose from, sometimes the page will display the same content strings twice in a row. </p>

</body> </html> ----------------------------------------------------%% #1 This is a great day!! %% #2 <h1>Smile</h1> %% #3 <img src="smiley.gif"> %% #4 Here's a <a href="http://www.w3schools.com">link.</a> -----------------------------------------------------------------Content Linking Example 80 :Build a table of contents <html> <body> <p> The example below builds a table of contents. </p> <% dim c dim i set nl=server.createobject("MSWC.Nextlink") c = nl.GetListCount("text\links.txt") i=1 %> <ul> <%do while (i <= c) %> <li><a href="<%=nl.GetNthURL("text\links.txt", i)%>"> <%=nl.GetNthDescription("text\links.txt", i)%></a> <% i = (i + 1) loop %> </ul> <p> The text file contains a list of page urls and link descriptions. It contains one line of text for each page. Note that the url and description MUST be separated by the TAB character. </p> <p> <a href="text/links.txt"><img border="0" src="/images/btn_view_text.gif"></a> </p>

</body> </html> -----------------------------------------------------------------asp_intro.asp ASP Intro asp_syntax.asp ASP Syntax asp_variables.asp ASP Variables asp_procedures.asp ASP Procedures ---------------------------------------------------------------------Example 81 :Navigate between pages in a text file <html> <body> <h1> This is page 1! </h1> <% Set nl=Server.CreateObject("MSWC.NextLink") If (nl.GetListIndex("text/links2.txt")>1) Then %> <a href="<%Response.Write(nl.GetPreviousURL("text/links2.txt"))%>">Previous Page</a> <%End If%> <a href="<%Response.Write(nl.GetNextURL("text/links2.txt"))%>">Next Page</a> <p>The example uses the Content Linking Component to navigate between the pages in a text file.</p> <p> <a href="text/links2.txt"><img border="0" src="/images/btn_view_text.gif"></a> </p> </body> </html>

-----------------------------------------demo_contentlinking2.asp Page 1 page2.asp Page 2 page3.asp Page 3 -----------------------------------------------

You might also like