Вы находитесь на странице: 1из 68

Created by saurabh singh naruka lecturer marudhar defence girls college merta city nagaur HTML dk ifjp; %&

Html : html ,d scripting language gSA html dk iqjk uke hyper text markup language gSA html dk mi;ksx web page vFkok website cukus ds fy, fd;k tkrk gSA osc istks dks leqg osc lkbV dgykrh gSA HTML Vsx ds izdkj %& ,p Vh ,e ,y es Vsx gksrs gS vkSj izR;sd Vsx dk viuk ,fVC;wV vkSj eku gksrk gSA Vsx czkmtj dks lwpuk nsrs gS fd mudks osc ist ij vko;drkuqlkj fn[kk;k tk;sA Vsx nks izdkj ds gksrs gS %& 1 d.Vsuj Vsxl~ container Tags 2 ,EIVh Vsxl~ Empty Tags

1 container Tags %& d.Vsuj Vsx VsDLV ds [k.M section ij yxrs gS d.Vsuj
Vsx dks ,d vkWifuax Vsx ,d Dyksftax Vsx dh vkoldrk gksrh gS tks [k.M ds nksuksa rjQ yxrs gSaA ysfdu Dyksftax Vsx esa lcls igys Lysk / yxkrs gSA mnkgj.k %& <P> vkSj </P> <B> vkSj </B> 2 Empty Tags %& ,EIVh Vsx vdsys Vsx gksrs gS tks VsDLV ij izHkko ugha Mkyrs gSA ,EIVh Vsx esa vkWifuax Vsx gksrk gS ysfdu Dyksfxat Vsx dh vko;drk ugh gksrh gSA mnkgj.k %& <HR> ----------------------------------------------------------------------------------------------------------------------------------------------------,fVz~C;wVl~ (Attributes) %& Vsx dk O;ogkj ,fVC;wV dk mi;ksx dj cnyk tk ldrk gSA ,d Vsx ds dbZ ,fVC;wV gks ldrs gSA ,fVC;wV ds eku dk Mcy dksVsku esa can djuk pkfg,A

Html ds ewy Vsx %& (i) HTML TAG :- ;g ,d dUVsuj Vsx gS vkSj nLrkost ds var esa Dyksftax Vsx dh vko;drk gksrh gSA ;g Vsx czkmtj dks crkrk gS fd ;g Qkby ,p Vh ,e ,y dh gSA mnkgj.k %& <html> vkSj </html> (ii) HEAD TAG :- khkZ [k.M nLrkost ds ckjs es lwpuk j[krk gSA khkZ Vsx Hkh ,d dUVsuj Vsx gS VkbVy Vsx blds ckn vkrk gSA mnkgj.k %& <head> vkSj </head>

(iii) TITLE TAG :- ;g Vsx czkmtj ds VkbVy ckj esa VkbVy dks izdV djus dh vuqefr nsrk gS ;g flQkfjk djrk gS fd VkbVy esa lk/kkj.k VsDLV gksuk pkfg, dksbZ best ;k fyad ughA mnkgj.k %& <Title> vkSj </Title> (iv) BODY Section :- ;g Vsx nLrkost dk gn; gksrk gS ckWMh og gS tgkW okLrfod oscist ij iznfkZr gksus ds fy, curk gSA ckWMh Vsx ] gsM Vsx ds fcYdqy ckn esa vkrk gS czkmtj lHkh fok;ksa dks fn[kkrk gS tks fd ckWMh Vsx ds vksifuax vkSj Dyksftax ds e/; vkrs gSaA mnkgj.k %& <BODY> vkSj </BODY>

HTML
Q1. vkMZj fyLV ds }kjk buiqV fMokbt fn[kkus ds fy, ,d html code fyf[k,A Html Code: <html> <head><title>board of secondary education</title></head> <body> <ol> list of input devices : <li>key board</li> <li>mouse</li> </ol>

<ol type = i> list of input devices : <li> key board </li> <li > mouse </li> <li value = 10> optical character reader </li> <li> scanner </li> </ol> </body> </html>

Output:

----------------------------------------------------------------------------------------Q2. Html es ,d osc ist cukb;s ftlesa fiDpj fn[kk;s rFkk Ldwy dk uke iznfkr gksA
Html Code: <html> <head><title>MDS</title></head> <body background = c:\web\sunset.jpg> <center>marudhar defence sr. sec. school</center> </body> </html>

Output:

Q3. vU; html ist ds fy, hyper link cukus gsrq html dksM fyf[k,A Html Code: <html> <head><title>marudhar</title></head> <body><a href = c:\web\gandhi.html>about gandhi</a></body> </html>

gandhi.html <html> <head><title>marudhar</title></head> <body text = red>father of the nation<body> </html>

Output:

(1)Asp D;k gSA \ Asp ,d ekbdzkslkQV VsDusyksth gS tks baVjusV vkSj osc ist ds chp bUVj,sDku djkrh gSA ;g dsoy html dk ,DVsuu gS tks fd ljoj lkbM ij ju gksrh gS bles client browser dk mi;ksx ugh gksrk gS blesa lkjk dke ljoj ij gksrk gSA -----------------------------------------------------------------------------------------------------------------------------------------(2) IIS dks Install djus ds pj.k fyf[k,A
(1) Start Button -->

Setting option --> control panel --> add/remove programs icon dk pquko djA

(2) sa add/remove windows components es ls add/remove window dk p;u djsaA (3) ;g window components dh fyLV nkkZ;sxh blesa ls IIS ds check box dks pquuk

iMsxkA blds ckn ok ij click djsaA


(4) blds ckn inetpub uke dk QksYMj ;k esa cu tk;sxkA (5) blds vUnj ,d Sub directory gksrh gS ftldk uke wwwroot gksrk gSA (6) blds ckn ge wwwroot directory esa vius uke dk folder cuk;asxs vksj asp esa cuh

gqbZ Qkby dks vius uke ds QksYMj esa lqjf{kr djsxsaA


(7) Ckuh gqbZ asp file Qkby dks ju djus ds fy, ge ckmtj fo.Mks Eksa fuEufyf[kr

URL dk mi;ksx djrs gSA URL = http://localhost/foldername/filename.asp ,UVj djus ij Qkby esa cus gq, dksM dk vkmViqV gesa ckmtj ij iznfkZr gks tkrk gSA

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Vbscript
Ex 4: Hello

<User Name> dks osc ist ij iznfkr djus gsrq ,d izksxzke fyf[k,A

<html> <head><title>-Show User Name-</title> <script language="VBScript"> sub newpages(txt)

document.writeln("Hello " + txt) end sub </script> </head> <body> <form name="form1" method="post" action=""> <p>Enter User Name <input name="t1" type="text" id="t1"></p> <p> <input type="submit" name="Submit" value="Enter" onClick="newpages(form1.t1.value)"> </p> </form> <h3>This is Working ON Internet Explorer</h3> </body> </html>

Output:

Ex 5: ,d osc ist cukb, tks eSlst ckDl ds lkFk fuEu lansk iznfkr djs : welcome to my web site

<html> <head><title>-Display Message Box-</title> <script language="VBScript"> sub msgs() msgbox("Welcome To My Web Site")

end sub </script> </head>

<body> <form name="form1" method="post" action=""> <p> <input type="submit" name="Submit" value="Message"onClick="msgs()"> </p> </form> <h3>This is Working ON Internet Explorer</h3> </body> </html>

Output:

-------------------------------------------------------------------------------------------------------------------Ex 6: ,d Vbscript dksM fyf[k, tks Length, Breadth rFkk Height dks ysrs gq, Area

of rectangle dks

iznfkr djsA

<html> <head><title>-Area Of Rectangle-</title> <script language="VBScript"> sub area() dim l,b,h,ar l=form1.l.value b=form1.b.value

h=form1.h.value ar=l*b*h msgbox("Area " & ar) end sub </script> </head>

<body onLoad="changecolor()">

<form name="form1" method="post" action="">

Length <input name="l" type="text" id="l"> Breadth <input name="b" type="text" id="b"> Height <input name="h" type="text" id="h"> <br>

<CENTER> <input type="button" name="Button" value="Area" onClick="area()"> </CENTER> </form> </body> </html>

Output:

Ex 7: Create a program to generate a hit counter.

<html> <head><title>-Hit Counter-</title>

<script language="VBScript"> sub msgs() msgbox("Welcome To My Web Site") end sub </script>

<script language="VBScript"> dim counter counter=0 sub count() counter=counter+1 msgbox("Counter : " & counter) end sub

</script> </head>

<body> <form name="form1" method="post" action=""> <div align="center"> <input type="button" name="Button" value="Hit Me" onClick="count()"> </div> </form> </body> </html>
Output:

---------------------------------------------------------------------------------------------------

Ex 8: vbscript

dk mi;ksx djrs gq, calculator dk fuekZ.k fdft,A

Code:

<html> <head><title>-Calculator-</title> <script language="VBScript"> sub calc(ch) if(ch="=")then form1.t.value= eval(form1.t.value) else if(ch="C") then form1.t.value= "" else form1.t.value=form1.t.value & ch end if end if end sub </script> </head> <body onLoad="getTimes()"> <form name="form1" method="post" action=""> <input name="t" type="text" id="t"> <br> <input type="button" name="Button" value="7" onClick="calc('7')"> <input type="button" name="Submit2" value="8" onClick="calc('8')"> <input type="button" name="Submit3" value="9" onClick="calc('9')"> <input type="button" name="Submit4" value="+" onClick="calc('+')"> <br> <input type="button" name="Submit5" value="4" onClick="calc('4')"> <input type="button" name="Submit6" value="5" onClick="calc('5')"> <input type="button" name="Submit7" value="6" onClick="calc('6')">

<input type="button" name="Submit8" value="-" onClick="calc('-')"> <br> <input type="button" name="Submit9" value="1" onClick="calc('1')"> <input type="button" name="Submit10" value="2" onClick="calc('2')"> <input type="button" name="Submit11" value="3" onClick="calc('3')"> <input type="button" name="Submit12" value="*" onClick="calc('*')"> <br> <input type="button" name="Submit13" value="0" onClick="calc('0')"> <input type="button" name="Submit14" value="C" onClick="calc('C')"> <input type="button" name="Submit15" value="=" onClick="calc('=')"> <br> </form> </body> </html>

Output:

Ex 9: ,d izksxzke fyf[k, tks null or empty string gksus ij lansk iznfkr djsA

Code:

<html> <head><title>-Check Null Or Empty String-</title> <script language="VBScript">

sub check() if(form1.t.value="")then msgbox("Enter The Text") form1.t.focus() else alert("Thank You") end if end sub </script> </head>

<body>

<form name="form1" method="post" action=""> Enter a Text<input name="t" type="text" id="t"> <input type="submit" name="Submit" value="Submit" onClick="check()"> </form>

</body>

</html>

Output:

----------------------------------------------------------------------------------------------------------------

Ex 10: ,d Qkse dk fuekZ.k fdft, ftles Email field gksA RkFkk bls osfyMsV djus ds fy, ,d vbscript dksM fyf[k,A

Code:

<html> <head><title>-E Mail Validation-</title>

<script language="VBScript">

sub check() if(form1.t.value="")then alert("Enter The Text") form1.t.focus() else dim email,a,d,diff,k,c

email=form1.t.value a=InStr(1,email,"@") d=InStr(1,email,".") diff=d-a k=d+1 c=Mid(email, k, 1) if(a<1 or diff<=1 or c="")then alert("Invalid Email ID") form1.t.focus() end if end if end sub

</script>

</head>

<body>

<form name="form1" method="post" action=""> Enter Email ID <input name="t" type="text" id="t"> <input type="submit" name="Submit" value="Submit" onClick="check()"> </form>

</body> </html>

Output:

-----------------------------------------------------------------------------------------------------

Ex 11: fuEufyf[kr fQYM dk mi;ksx djrs fg, ,d Qkse dk fuekZ.k fdft, rFkk bUgs osfyMsV djus ds fy, vbscript dksM fyf[k,A Name - textbox Address - textbox Date Of Birth - Combo box Email - textbox

Code:

<html> <head><title>-Area Of Rectangle-</title>

<script language="VBScript"> sub check() if(form1.n.value="")then alert("Enter The Name") form1.n.focus()

elseif(form1.a.value="")then alert("Enter The Address") form1.a.focus()

elseif(form1.y.value="")then alert("Enter The Year") form1.y.focus()

elseif(form1.d.value="")then alert("Select The Day") form1.d.focus()

elseif(form1.m.value="")then alert("Select The Month") form1.m.focus()

elseif(form1.mail.value="")then dim email,a,d,diff,k,c email=form1.t.value a=InStr(1,email,"@") d=InStr(1,email,".") diff=d-a k=d+1 c=Mid(email, k, 1) if(a<1 or diff<=1 or c="")then alert("Invalid Email ID") form1.t.focus()

end if

end if end sub </script> </head>

<body>

<form name="form1" method="post" action=""> <p> Name<input name="n" type="text" id="n">

<br><br> Address<input name="a" type="text" id="a">

<br><br> Date Of Birth : Day

<select name="d" id="d" > <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> < option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</ option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select>

Month<select name="m" id="m"> <option value="1">Jan</option> <option value="2">Feb</option> <option value="3">Mar</option> <option value="4">Aprl </option><option value="5">May</option><option value="6">Jun</option> <option value="7">July</option><option value="8">Aug</option><option value="9"> Sep</option> <option value="10">Oct</option><option value="11">Nov</option><option value="12">Dec</option>

</select>

Year<input name="y" type="text" id="y" size="6"> <br><br>

Email Id <input name="mail" type="text" id="mail"> <br> <br> <input type="button" name="Button" value="- Submit -"onClick="check()">

</form> </body> </html>

Output:

-----------------------------------------------------------------------------------------------------------------------------------

Ex 9: Create a program the accepts the time from the system clock and accordingly displays a Good morning, Good Afternoon and Good Evening message to the user.

<html> <head><title>-Greeting Acording to Time-</title> <script language="VBScript"> sub wish() dim h h=Datepart("h",Now) if h>=1 and h<=12 then msgbox("Good Morning") elseif h>=13 and h<=18 then msgbox("Good Afternoon") else msgbox("Good Evening") end if end sub </script> </head> <body onLoad="wish()"></body> </html>

Output:

------------------------------------------------------------------------------------------------------------------------Ex 12: ,d izksxzke fyf[k, ftles For next Looping Statements dk mi;ksx djrs gq, Fibonacci Series generate fdft,A

<html> <head><title>-Fibonacci Series-</title> <script language="VBScript"> sub fib() dim a,b,c a=1 b=1 document.write("First 10 Fibonacci Series<br>") document.write(a & "&nbsp;&nbsp;" & b & "&nbsp;&nbsp;") for i=3 to 10 c=cint(a)+cint(b) document.write(c & "&nbsp;&nbsp;") a=b b=c next end sub </script> </head> <body onLoad="fib()"></body> </html>

Output:

--------------------------------------------------------------------------------Ex 13: Do While Loop dk mi;ksx djrs gq, Factorial Series Kkr djus dk vbscript code fyf[k,A.

<html> <head><title>-Factorial Number-</title> <script language="VBScript"> sub fact(n) dim f,i f=1 i=1 do while(i<=cint(n)) f=cint(f)*cint(i) i=i+1 loop document.write("<br>Factorial Of " & n & " is " & f) end sub </script> </head> <body>

<form name="form1" method="post" action=""> <input name="n" type="text" id="n"> <input name="Button" type="button" onClick="fact(form1.n.value)" value="Factorial"> </form> </body> </html>

Output:

---------------------------------------------------------------------------------------------------------------------

Ex 14: ,d izksxzke fyf[k, tks multiplication of two matrices dks iznfkr djsA

<html> <head><title>-Multiplication of Two Matrics-</title> <script language="VBScript"> sub matmul() dim m1(3,3),m2(3,3),m3(3,3),count,i,j count=0 msgbox("Enter First matrix") for i=0 to 2 for j=0 to 2

m1(i,j)=inputbox("") next next msgbox("Enter Second matrix") for i=0 to 2 for j=0 to 2 m2(i,j)=inputbox("") next next document.write("<br>Product of two Matrix<br>") for i=0 to 2 for j=0 to 2 for k=0 to 2 m3(i,j)=cint(m3(i,j))+cint(m1(i,k))* cint(m2(k,j)) next next next for i=0 to 2 for j=0 to 2 document.write(" " & m1(i,j)) next document.write("<br>") next document.write("<br>+<br>") for i=0 to 2 for j=0 to 2 document.write(" " & m2(i,j)) next document.write("<br>") next

document.write("<br>=<br>") for i=0 to 2 for j=0 to 2 document.write(" " & m3(i,j)) next document.write("<br>") next end sub </script> </head> <body onLoad="matmul()"></body> </html>

Output:

-------------------------------------------------------------------------------------------------------------------------------------Ex 15: ,d izksxzke fyf[k, tks user ls buiqV ysdj Factorial fd x.kuk djs ijUrq

rHkh ;nh l[;k prime number gksA

<html> <head><title>-Prime to Factorial-</title> <script language="VBScript"> sub ChkPrime(n)

dim i,prime,k prime=true for i=2 to cint(n)/2 if (n Mod i)=0 then prime=false end if next if prime=true then fact(n) else document.write("<br>The Number is Not Prime") end if end sub sub fact(n) dim f,i f=1 i=1 do while(i<=cint(n)) f=cint(f)*cint(i) i=i+1 loop document.write("<br>Factorial Of " & n & " is " & f) end sub </script> </head>

<body> <form name="form1" method="post" action=""> <input name="n" type="text" id="n"> <input name="Button" type="button" onClick="ChkPrime(form1.n.value)"value="- Factorial -">

</form> </body> </html>

Output:

ASP
(16) response.write Command dk mi;ksx djrs gq, ,d fyf[k, rFkk

vkmViqV ckmtj es iznfkZr fdft,A

<html> <body> <% response.write("My first ASP script!") %> </body> </html>

Output: My first ASP script!

ASP Variables (17) osfj,cy dks fMdys;j djds eku iznku djrs gq, bl eku dks mi;ksx es ysus gsrq vko;d Asp Code fyf[k,A

<html> <body> <% dim name name="saurav" response.write("My name is: " & name) %> </body> </html>

Output:

My name is: saurav

(18) ,sjs dks fMdys;j djrs gq, bles lqjf{kr eku dsk czkmtj es iznfkr djus gsrq ,d , ,l ih dksM fyf[k,A

<html> <body> <% Dim famname(5),i famname(0) = "ajay" famname(1) = "vijay" famname(2) = "ram" famname(3) = "Sita" famname(4) = "Hanuman" famname(5) = "rahul"

For i = 0 to 5 response.write(famname(i) & "<br>") Next %> </body> </html>

Output: ajay vijay ram Sita hanuman rahul

(19) Html heading tag dk ASP es mi;ksx djrs gq, ifj.kke dks screen ij iznfkr fdft,A

<html> <body> <% dim i for i=1 to 6 response.write("<h" & i & ">Heading " & i & "</h" & i & ">") next %> </body> </html>

Output:

Heading 1
Heading 2

Heading 3
Heading 4
Heading 5
Heading 6

(20) Asp es ,d dksM fyf[k, ftles le; ds vuqlkj greatting (good morning or good day) iznfkr gksA <html> <body> <% dim h h=hour(now()) response.write("<p>" & now()) response.write("</p>") If h<12 then response.write("Good Morning!") else response.write("Good day!") end if %> </body> </html> Output: 11/18/2012 12:32:02 AM Good Morning! Conditional Statement

(21)If ... Then ... Else Statement dk mi;ksx djrs gq, fo}kFkh ds izkIr ifj.kke ds vuqlkj grade iznfkr fdft,A <%@ language="vbscript"%> <% Dim Result Result = 70

if Result >= 75 then response.write("Passed: Grade A <br />") elseif Result >= 60 then response.write("Passed: Grade B <br />") elseif Result >= 45 then response.write("Passed: Grade C <br />") else response.write("Failed <br />") end if %>

Output : passed Grade B

(22) If..Then.Else Statement dk mi;ksx djrs gq, ,d asp dksM fyf[k, ftles orZeku ekg ds vuqlkj lnsk iznfkr gksA <html> <body> <script type="text/vbscript"> Option Explicit Dim m m = Month(Date) if m = 1 then

document.write ("A new year has arrived. What are your plans?") elseif m = 4 then document.write("April showers bring May flowers!") elseif m = 7 then document.write("Summer! Watermelon! Yayy!!") elseif m = 11 then document.write("Leaves all over the place") else document.write("No particular message for this month") end if </script> </body> </html> Output: No particular message for this month --------------------------------------------------------------------------------------------------------------------------------------------------(23) Select Case dk mi;ksx djrs gq, ,d asp dksM fyf[k, ftles orZeku ekg ds vuqlkj

lnsk iznfkr gksA


<html> <body> <script type="text/vbscript"> Option Explicit Dim m m = Month(Date)

Select Case m case 1 document.write ("A new year has arrived. What are your plans?") case 4 document.write("April showers bring May flowers!") case 7 document.write("Summer! Watermelon! Yayy!!")

case 11 document.write("Leaves all over the place") case else document.write("No particular message for this month") end select </script> </body> </html> Output: No particular message for this month

Conditional Statement
(24) Do loop dk mi;ksx djrs gq, 1 ls 5 rd fd l[;k iznfkr fdft,A

<% Dim i i=0 Do While i<=5 response.write(i & "<br \>") i=i+1 Loop %> Output: 1 2 3 4 5

-------------------------------------------------------------------------------------------------------------------------------(25) For Loop dk mi;ksx djrs gq, 1 ls 5 rd fd l[;k screen ij iznfkr fdft,A

<%@ language="vbscript" %> <% For i = 0 to 5 Step 2 response.write("The number is " & i & "<br />") Next %>

Output: 1 2 3 4 5 ------------------------------------------------------------------------------------------------------------------------------

ASP Procedures
(26) Procedures vFkok subroutine dks fMdys;j djrs gq, bls call djus dk Asp dksM fyf[k,A izksfltj es nks la[;kvks dks tksMus dk dksM fy[kk x;k gS

<html>

<head> <% sub vbproc(num1,num2) response.write(num1*num2) end sub %> </head>

<body> <p>You can call a procedure like this:</p> <p>Result: <%call vbproc(3,4)%></p> <p>Or, like this:</p> <p>Result: <%vbproc 3,4%></p> </body> </html>

Output: You can call a procedure like this: Result: 12 Or, like this: Result: 12

ASP Forms and User Input


(27) Get esFkM dk mi;ksx djrs gq, ,d Form dk fuekZ.k fdft,A ftles textbox es ;qtj dk uke buiqV djk dj uke dks screen ij iznfkZr fdft,A

<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>

Output:

(28) Post esFkM dk mi;ksx djrs gq, ,d Form dk fuekZ.k fdft,A ftles textbox es ;qtj dk uke buiqV djk dj uke dks screen ij iznfkZr fdft,A

<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>

Output:

(29)

Radio button dk mi;ksx djrs gq, ,d Form dk fuekZ.k fdft,A ftles radio button ij click dj fn, x, dkj ds uke dks pqudj dkj dk uke screen ij iznfkZr fdft,A

<html> <% dim cars cars=Request.Form("cars") %> <body> <form action="radio.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>

Output:

ASP Cookies
(30) ,d cookie dk fuekZ.k fdft, tks osc lkbV dks foftV djus okys users fd la[;k iznfkr djs A

<% 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>

Output: You have visited this Web page 1 time before!

ASP Request Object


Use: The Request object is used to get information from a visitor.

(31) Checkbox dk mi;ksx djrs gq, ,d Form dk fuekZ.k fdft,A ftles Check button ij click dj fn, x,
Qyks ds ukeks es ls ialn ds Qyks dks pqudj Qyks ds uke screen ij iznfkZr fdft,A

<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>

Output:

-------------------------------------------------------------------------------------------------------------------------------

ASP Server Object

(32)

Text Qkby dks open djds Read djus ds fy, ,d Asp code fyf[k,A

<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 src="/images/btn_view_text.gif"></a> </p> </body> </html>

Output:

,d counter dk fuekZ.k fdft, ftlds }kjk visit fd, tkus okys;qtj fd la[;k iznfkr djsA
(33) <% 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 %> <!DOCTYPE html> <html> <body> <p> This page has been visited <%=fcount%> times. </p> </body> </html> Output: This page has been visited 12345 times.

ASP TextStream Object (34) Text Qkby dks open djds Read djus ds fy, ,d Asp code fyf[k,A

<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>

Output: This is the text in the text file: Hello! How are you today?

(35) VsDlV Qkby dks vksiu djds VsDlV Qkby ds fuffpr Hkkx dks jhM djus ds fy, ,d Asp code fyf[k,A

<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>

Output:
This is the first five characters from the text file: Hello

(36) VsDlV Qkby dks vksiu djds VsDlV Qkby fd flQZ ,d ykbu dks jhM djus ds fy, ,d Asp code fyf[k,A

<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>

Output:
This is the first line of the text file: Hello!

(37) VsDlV Qkby dks vksiu djds VsDlV Qkby fd lHkh ykbu dks jhM djus ds fy, ,d Asp code fyf[k,

<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>

Output:
This is all the lines in the text file: Hello! How are you today?

(38) VsDlV Qkby dks vksiu djds VsDlV Qkby ds fdlh fuffpr Hkkx dks skip/NksMrs gq, ckdh Hkkx dks jhM djus ds fy, ,d Asp code fyf[k,

<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>

Output:
The first four characters in the text file are skipped: o! How are you today?

(39) VsDlV Qkby dks vksiu djds VsDlV Qkby es ls fdlh ,d ykbu dks NksM dj ckdh ykbu dks jhM djus ds fy, ,d Asp code fyf[k,
<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>

Output:

The first line in the text file is skipped: How are you today?

(40) VsDlV Qkby dks vksiu djds VsDlV Qkby fd lHkh ykbu dks ykbu uEcj lfgr iznfkZr djus gsrq ,d Asp code fyf[k,A

<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>

Output: This is all the lines in the text file (with line numbers): Line:1 Hello! Line:2 How are you today?

(41)

Get column number (How to get the column number of the current character in a 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>

Output:
He The cursor is now standing in position 3 in the text file

ASP Components
ASP AdRotator Component (42) ,d ,M jksVsVj dEiksusUV dk mi;ksx djrs gq, ,d foKkiu dk fuekZ.k fdft, tks czkmtj fd screen ij iznfkr gksA
USE:- The ASP AdRotator component creates an AdRotator object that displays a different image
each time a user enters or refreshes a page. A text file includes information about the images.

<% url=Request.QueryString("url")

If url<>"" then Response.Redirect(url) %> <!DOCTYPE html> <html> <body> <% set adrotator=Server.CreateObject("MSWC.AdRotator") adrotator.TargetFrame="target='_blank'" 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>NOTE: The AdRotator does not work with Internet Information Server 7 (IIS7).</p> <p> <a href="text/advertisements.txt"> <img src="/images/btn_view_text.gif"></a> </p> </body> </html>

Output:

ASP Browser Capabilities Component


(43) Browser capabilities component dk mi;ksx dj mi;ksx fd, tk jgs ckmtj dk Vkbi ]ojtu ] vksijsfVx flLVe vkfn tkudkjh czkmtj fd screen ij iznfkr fdft, A
<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>

Output: Client OS Web Browser Browser version Frame support? Table support? Sound support? Cookies support? VBScript support? JavaScript support? unknown Opera 3.60 True True True True False True

ASP Content Rotator Component


(44),d dUVsUV jksVsVj dEiksusUV dk mi;ksx djrs gq, ,d foKkiu dk fuekZ.k fdft, tks czkmtj fd screen ij iznfkr gksA RkFkk gj ckj tc Hkh ;qtj ist dks djs rc foKkiu ifjofrZr gksrk jgsA
<html> <body> <p> <a href="demo_textads.asp"><img 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>

Output:

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.

ASP ADO
USE:- ADO dk mi;ksx osc ist ds tfj, MkVkcsl dks ,Dlsl djus ds fy, fd;k tkrk gSA

ASP Page ds tfj, MkVkcsl dk mi;ksx :-:


(1) MkVkcsl ds lkFk ADO dusDku LFkkfir fdft, (2) MkVkcsl dusDku dks vksiu fdft, (3) ADO recordset dks create fdft, (4) recordset dks vksiu fdft, (5) recordset ls vko;d MkVk dks izkIr djrs gS (6) recordset dks can djrs gS (7) connection dks can djrs gS

(1)

Create a DSN-less Database Connection

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open "c:/webdata/northwind.mdb" %> (2) Create an ODBC Database Connection

<% set conn=Server.CreateObject("ADODB.Connection") conn.Open "northwind" %> An ODBC Connection to an MS Access Database Here is how to create a connection to a MS Access Database: 1. 2. 3. 4. 5. 6. 7. Open the ODBC icon in your Control Panel. Choose the System DSN tab. Click on Add in the System DSN tab. Select the Microsoft Access Driver. Click Finish. In the next screen, click Select to locate the database. Give the database a Data Source Name (DSN). Click OK.

ADO Examples

Display (45) MS access fd Vscy lqjf{kr fjdksMks dks osc ist es iznfkr fdft,A
<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") rs.Open "Select * from papa", conn

do until rs.EOF for each x in rs.Fields Response.Write(x.name) Response.Write(" = ") Response.Write(x.value & "<br>") next Response.Write("<br>") rs.MoveNext loop

rs.close conn.close %>

</body> </html>

Output:

----------------------------------------------------------------------------------------------------------(46)

fjdksMks dks Html Vscy es iznfkr fdft,A

Display records in an HTML table


<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb"

set rs = Server.CreateObject("ADODB.recordset") rs.Open "SELECT roll, name, age FROM papa", conn %>

<table border="1" width="100%"> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr>

<%loop rs.close conn.close %> </table>

</body> </html>

Output:

(47)

headers dks HTML Vscy es tksMuk rFkk HTML Vscy es dyj MkyukA

<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") sql="SELECT roll, name, age FROM papa" rs.Open sql, conn %>

<table border="1" width="100%" bgcolor="#fff5ee"> <tr> <%for each x in rs.Fields

response.write("<th align='left' bgcolor='#b0c4de'>" & x.name & "</th>") next%> </tr> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close %> </table>

</body> </html>

Output:

Queries
(48) osc ist es flQZ mUgh fjdksM dks iznfkr fdft, ftudk uke a kCn ls kq: gksrk gSA

<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") sql="SELECT roll, name ,age FROM papa WHERE name LIKE 's%'" rs.Open sql, conn %>

<table border="1" width="100%"> <tr> <%for each x in rs.Fields response.write("<th>" & x.name & "</th>") next%> </tr> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close

%> </table>

</body> </html>

Output:

-------------------------------------------------------------------------------------------------------------

(49) osc ist es flQZ 50 lky ls vf/kd mae okys yksxks ds fjdksM iznfkr fdft,A
<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") sql="SELECT roll, name, age FROM papa WHERE age= 50" rs.Open sql, conn %>

<table border="1" width="100%"> <tr> <%for each x in rs.Fields response.write("<th>" & x.name & "</th>") next%> </tr> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%> </td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close %> </table>

</body> </html>

Output:

(50)fjdkMZ dks Filter djd osc ist es iznfkZr fdft,A


<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\Customers.mdb"

set rs=Server.CreateObject("ADODB.recordset") sql="SELECT DISTINCT Country FROM Customers ORDER BY Country" rs.Open sql,conn

country=request.form("country")

%>

<form method="post"> Choose Country <select name="country"> <% do until rs.EOF response.write("<option") if rs.fields("country")=country then response.write(" selected") end if response.write(">") response.write(rs.fields("Country"))

rs.MoveNext loop rs.Close set rs=Nothing %> </select> <input type="submit" value="Show customers"> </form>

<% if country<>"" then sql="SELECT Companyname,Contactname,Country FROM Customers WHERE country='" & country & "'" set rs=Server.CreateObject("ADODB.Recordset") rs.Open sql,conn %> <table width="100%" cellspacing="0" cellpadding="2" border="1"> <tr> <th>Companyname</th> <th>Contactname</th> <th>Country</th> </tr> <% do until rs.EOF response.write("<tr>") response.write("<td>" & rs.fields("companyname") & "</td>") response.write("<td>" & rs.fields("contactname") & "</td>") response.write("<td>" & rs.fields("country") & "</td>") response.write("</tr>") rs.MoveNext loop rs.close conn.Close

set rs=Nothing set conn=Nothing%> </table> <% end if %> </body> </html>

Output:

SORT
(51) fjdksMks dks fQYM use ds vuqlkj vlsfUMx vkMZj es lksVZ djds osc ist es iznfkr fdft,A
<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") sql="SELECT roll, name, age FROM papa ORDER BY name" rs.Open sql, conn %>

<table border="1" width="100%"> <tr> <%for each x in rs.Fields response.write("<th>" & x.name & "</th>") next%> </tr> <%do until rs.EOF%>

<tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close %> </table> </body> </html>

Output:

(52) fjdksMks dks fQYM use ds vuqlkj fMlsfUMx vkMZj es lksVZ djds osc ist es iznfkr fdft,A Sort the records on a specified fieldname descending
<html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") sql="SELECT roll, name, age FROM papa ORDER BY name DESC" rs.Open sql, conn

%>

<table border="1" width="100%"> <tr> <%for each x in rs.Fields response.write("<th>" & x.name & "</th>") next%> </tr> <%do until rs.EOF%> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <%loop rs.close conn.close %> </table> </body> </html>

Output:

(53) ,d asp code fyf[k, ftles ;qtj viuh vko;drk ds vuqlkj dksye dks lksVZ djus ds fy, pqu ldsA

<html> <body>

<table border="1" width="100%" bgcolor="#fff5ee"> <tr> <th align="left" bgcolor="#b0c4de"> <a href="recordset.asp?sort=companyname">Company</a> </th> <th align="left" bgcolor="#b0c4de"> <a href="recordset.asp?sort=contactname">Contact</a> </th> </tr> <% if request.querystring("sort")<>"" then sort=request.querystring("sort") else sort="companyname" end if

set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kamal.mdb" set rs=Server.CreateObject("ADODB.recordset") sql="SELECT Companyname,Contactname FROM Customers ORDER BY " & sort rs.Open sql,conn

do until rs.EOF response.write("<tr>") for each x in rs.Fields response.write("<td>" & x.value & "</td>") next rs.MoveNext response.write("</tr>")

loop rs.close conn.close %> </table> </body> </html> Output:

Recordset Object
(54) Vscy ds izFke dkWye ds izFke nks fjdksMZ dks rFkk bl ipkr izFke fjdksMZ ds izFke rhu dkWye dks osc ist ij iznfkr fdft,A GetRows
<html> <body>

<% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open"C:\inetpub\wwwroot\kh.mdb" set rs = Server.CreateObject("ADODB.recordset") rs.Open "Select * from papa", conn

'The first number indicates how many records to copy

'The second number indicates what recordnumber to start on p=rs.GetRows(2,0)

response.write("<p>This example returns the value of the first column in the first two records:</p>") response.write(p(0,0)) response.write("<br>") response.write(p(0,1))

response.write("<p>This example returns the value of the first three columns in the first record:</p>") response.write(p(0,0)) response.write("<br>") response.write(p(1,0)) response.write("<br>") response.write(p(2,0))

rs.close conn.close %>

</body> </html>

Output:

(55)Vscy fd flQZ strings dks osc ist ij iznfkr fdft,A GetString


<html> <body> <% set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("/db/northwind.mdb")) set rs = Server.CreateObject("ADODB.recordset") rs.Open "SELECT Companyname, Contactname FROM Customers", conn str=rs.GetString(,,"</td><td>","</td></tr><tr><td>"," ") %> <table border="1" width="100%"> <tr> <td><%Response.Write(str)%></td> </tr> </table> <% rs.close conn.close set rs = Nothing set conn = Nothing %> </body> </html>

Output:

Вам также может понравиться