ASP contains text, HTML tags and different scripts. These scripts in an ASP file are executed on the server.Before learning ASP one should have knowledge of VBscript or Java script.ASP means Active Server Pages and this pages runs on Internet Information Services .ASP file is the same as HTML file it contains HTML, XML, and scripts and these scripts are executed on server.ASP files are saved with extension.asp.
Features of ASP
1.It edits, changes and add different contents to a Web page.
2.It replies to user queries and to data whish submitted from HTML forms.
3.Access any data or databases and return the results to a browser.
4.It also customizes a Web page to make it more useful for every users.
In ASP if variables are declared outside a procedure they can be changed by any script and if declared inside the procedure they are created and destroyed every time the procedure is executed.In ASP Response object this object is used to send output to the user and in ASP Request object this object is used to get information from the user. Application object in ASP is used to tie files together and to store variables.Application object contains information which is used my many web pages in the application.In ASP Session object is used to store information for a specific user session.In object data hold information of one specific user and one specific application .
Now let us see in details regarding Loops
Do While...Loop
Example
<%
a=0
Do While a<5
response.write("Hello<hr />")
a=a+1
Loop
%>
In this example "a<5" and the instructions defines a response text and an increment of the variable "a". In the example, a will be increased until it gets a value of 5. Then the loop will be abandon. one can use many statements within the loop.
Do Until....Loop
Example
<br><span style="color: rgb(0, 0, 255); font-weight: bold;"><%<
/span><br>a=<span style="color: rgb(128, 0, 0);">0</span><
br><span style="color: rgb(153, 0, 153); font-weight: bold;">Do</span>
Until a=<span style="color: rgb(128, 0, 0);">5</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">response<
/span>.<span style="color: rgb(51, 0, 102);">write</span><
span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><
span style="color: rgb(204, 0, 0);">"Hello<hr />"</span><
span style="color: rgb(0, 102, 0); font-weight: bold;">)</span><br>
a=a<span style="color: rgb(128, 0, 0);">+1</span><br><
span style="color: rgb(153, 0, 153); font-weight: bold;">Loop</span><
br><span style="color: rgb(0, 0, 255); font-weight: bold;">%><
/span><br>
In this example "a=5", so a will increased until it is equal to 5 and then the loop will be abandon.
Select Case....End Select
Example
<br><span style="color: rgb(0, 0, 255); font-weight: bold;"><%<
/span><br> a=<span style="color: rgb(128, 0, 0);">5</span>
<br><span style="color: rgb(153, 0, 153); font-weight: bold;">Select<
/span> <span style="color: rgb(153, 0, 153); font-weight: bold;">Case<
/span> a<br> <span style="color: rgb(153, 0, 153); font-weight: bold;
">Case</span> <span style="color: rgb(128, 0, 0);">1</span><
br> <span style="color: rgb(153, 0, 153); font-weight: bold;">
Response</span>.<span style="color: rgb(51, 0, 102);">write</span>
<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><
span style="color: rgb(204, 0, 0);">"Number is 1"</span><
span style="color: rgb(0, 102, 0); font-weight: bold;">)</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Case</span>
<span style="color: rgb(128, 0, 0);">2</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Response<
/span>.<span style="color: rgb(51, 0, 102);">write</span>
<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><
span style="color: rgb(204, 0, 0);">"Number is 2"</span>
<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Case</span>
<span style="color: rgb(128, 0, 0);">3</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Response</span>
.<span style="color: rgb(51, 0, 102);">write</span>
<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><
span style="color: rgb(204, 0, 0);">"Number is 3"</span><
span style="color: rgb(0, 102, 0); font-weight: bold;">)</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Case</span>
<span style="color: rgb(128, 0, 0);">4</span><br> <
span style="color: rgb(153, 0, 153); font-weight: bold;">Response</span>
.<span style="color: rgb(51, 0, 102);">write</span>
<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><
span style="color: rgb(204, 0, 0);">"Number is 4"</span>
<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span><
br> <span style="color: rgb(153, 0, 153); font-weight: bold;">Case<
/span> <span style="color: rgb(128, 0, 0);">5</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Response<
/span>.<span style="color: rgb(51, 0, 102);">write</span> <
span style="color: rgb(0, 102, 0); font-weight: bold;">(</span><
span style="color: rgb(204, 0, 0);">"Number is 5"</span><
span style="color: rgb(0, 102, 0); font-weight: bold;">)</span><br>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Case</span>
<span style="color: rgb(153, 0, 153); font-weight: bold;">Else</span>
<br> <span style="color: rgb(153, 0, 153); font-weight: bold;">
Response</span>. <span style="color: rgb(51, 0, 102);">write<
/span> <span style="color: rgb(0, 102, 0); font-weight: bold;">
(</span><span style="color: rgb(204, 0, 0);">"a is higher than 5"<
/span><span style="color: rgb(0, 102, 0); font-weight: bold;">)<
/span><br><span style="color: rgb(153, 0, 153); font-weight: bold;
">End</span> <span style="color: rgb(153, 0, 153); font-weight: bold;
">Select</span><br><span style="color: rgb(0, 0, 255);
font-weight: bold;">%></span><br>
ASP.Net Database Connection
When we run the script on ASP server we will get the following page
By clicking the button is invoked the button1_Click event and then the data written in the text boxes is recorded to database.
Tags: ASP.Net, database connectionASP.Net Web Site Sample
Here we are defining the function, which will be called when the button is clicked.
It, will change the label text.
Debug the project (F5), and the web page will be opened, it will be something like this
Now write something in the textbox, and click the button. You will get this
So, with clicking the button, the label text property is changing to "TextBox text: " + the text we write in the text box.
Tags: ASP.Net, visual studio, web site
Subscribe to post feed