0% found this document useful (0 votes)
5 views

Built in Objects ASP

The document provides lecture notes on ASP.NET built-in objects, detailing the Request, Response, Server, Application, and Session objects used for accessing information related to web applications. It includes examples of using the Response object to write output and demonstrates the implementation of a C# foreach loop for iterating through collections. Additionally, a programming example is presented, showcasing the creation and management of an Accounts class and displaying account information using ASP.NET syntax.

Uploaded by

careermantra5500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Built in Objects ASP

The document provides lecture notes on ASP.NET built-in objects, detailing the Request, Response, Server, Application, and Session objects used for accessing information related to web applications. It includes examples of using the Response object to write output and demonstrates the implementation of a C# foreach loop for iterating through collections. Additionally, a programming example is presented, showcasing the creation and management of an Accounts class and displaying account information using ASP.NET syntax.

Uploaded by

careermantra5500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ASP.NET Dr.

Qadri Hamarsheh

ASP.NET Objects

Advanced Programming Language (630501)


Fall 2011/2012 – Lectures Notes # 19

ASP.NET Built-in Objects

Outline of the Lecture


 Introduction
 Response object
 Implementation of C# foreach loop
 Programming Example

Introduction
• Using ASP.NET built-in objects, you can access to information regarding the Web
server, the client who is accessing a Web page, the Web application that contains the
Web page, and the fields in the HTTP request and response streams.
• The Request, Response, Server, Application, and Session objects are part
of ASP.NET and are used in much the same way as they are in ASP. However, in
ASP.NET these objects are defined in new classes in the System.Web namespace.

Object Description
Application Describes the methods, properties, and collections of the object that
stores information related to the entire Web application, including
variables and objects that exist for the lifetime of the application.
Request Describes the methods, properties, and collections of the object that
stores information related to the HTTP request. This includes forms,
cookies, etc.
Response Describes the methods, properties, and collections of the object that
stores information related to the server's response. This includes
displaying content, manipulating headers, etc.
Server Describes the methods and properties of the object that provides
methods for various server tasks. With these methods you can execute

Page 1 of 5 1
ASP.NET Dr.Qadri Hamarsheh

ASP.NET Objects

code, get error conditions, encode text strings, create objects for use by
the Web page, and map physical paths.
Session Describes the methods, properties, and collections of the object that
stores information related to the user's session, including variables and
objects that exist for the lifetime of the session.

Response object

Response.Write Method

• Writes a variable or text to the current HTTP output as a string.

Examples:
Example 1 (string)
<%
Response.Write "Hello World"
%>
Output:
Hello World
Example 2.a (string with HTML Tags)
<%
Response.Write("Hello<br/>World")
%>
Output:
Hello
World
Example 2.a (string with HTML Tags)
<% Response.Write "<TABLE WIDTH = 100%\>" %>
Example 3 (variables and concatenation operators)
Int myNum = 25;
String myString = "Hello";
Response.Write("myNum = " + myNum + "<br />");
Response.Write("myString = " + myString +
this.TextBox1.Text + "<br />");

Page 2 of 5 2
ASP.NET Dr.Qadri Hamarsheh

ASP.NET Objects

Implementation of C# foreach loop


• foreach loop in C# help us to iterate through elements on a given collection on the
simplest possible way so that we can easily access the elements of the collection and do
some operations inside the loop.
• Syntax
foreach (Element_of_Collecion Variable_Name in Collection_Name )
{
//Code
}

Example 4 (using foreach structure with Response.Write )


int[] array = { 5, 10, 15, 20, 25 };
foreach (int number in array)
{
Response.Write(number + ",");
}
Example 5 (using foreach structure with Response.Write and ArrayList object)
ArrayList namesArrayList = new ArrayList();
namesArrayList.Add(“Mohammed”);
namesArrayList.Add(“Khaled”);
namesArrayList.Add(“Badr”);
foreach (string name in namesArrayList)
{
Response.Write(name + "...<br>");

Example 6 (Hide all mobile controls using foreach mechanism)


Homework!!!!!!!!!!!!!!!!!!!!!!!
• There are a few things that should be pointed out about this code as compared with the
for syntax.
o You don't have to know the bounds/dimentions of the array.
o It automatically gives you an instance (of the right type) of whatever is collected
by the array.
o The syntax (and therefore the resulting code) is just so much cleaner.
o This same syntax will work whether you're iterating over an array, ArrayList,
Hashtable or any other type of collection.
Page 3 of 5 3
ASP.NET Dr.Qadri Hamarsheh

ASP.NET Objects

Programming Example

Example 19-
19-1
<script language="C#"
language="C#" runat="server">
runat="server">
private class Accounts
{
long LUserID;
string SEmail,SFirst,SLast;
bool Bstatus;
public Accounts ( long id, string em, string f, string l, bool s)
{
LUserID= id; SEmail = em; SFirst = f;
SLast = l; Bstatus = s; }
public long UserID
{ get { return LUserID; } }
public string Email
{ get { return SEmail; } }
public string First
{ get { return SFirst; } }
public string Last
{ get { return SLast; } }
public bool Status
{ get { return Bstatus; } }
}
private void Page_Load ( object sender, EventArgs e)
{
ArrayList AccountList = new ArrayList ();
if (!IsPostBack)
{
AccountList.Add(new
AccountList.Add(new Accounts (1,"[email protected]"
(1,"[email protected]",
"[email protected]","Sami",
"Sami","Issa",
"Issa",true));
true));
AccountList.Add(new
AccountList.Add(new Accounts (2,"[email protected]"
(2,"[email protected]",
"[email protected]","Naji",
"Naji","Ali",
"Ali",false));
false));
AccountList.Add(new
AccountList.Add(new Accounts (3,"[email protected]"
(3,"[email protected]",
"[email protected]","Najeeb",
"Najeeb","Issa",
"Issa",true));
true));
AccountList.Add(new
AccountList.Add(new Accounts (4,"[email protected]"
(4,"[email protected]",
"[email protected]","Fadi",
"Fadi","Fawzi",
"Fawzi",true
true));
Page 4 of 5 4
ASP.NET Dr.Qadri Hamarsheh

ASP.NET Objects

Accounts FirstObj = (Accounts


(Accounts)AccountList[0];
Accounts)AccountList[0];
Response.Write("<b>First
Response.Write("<b>First Account Information</b></br>");
Information</b></br>");
Response.Write("<table
Response.Write("<table border='3'>");
border='3'>");
Response.Write("<tr ><th>UserID</th><th>Email</th><th>Status</th></tr>");
Response.Write("<tr ><th>UserID</th><th>Email</th><th>Status</th></tr>" );
Response.Write("<tr><td>"
Response.Write("<tr><td>"+FirstObj.UserID+
"<tr><td>"+FirstObj.UserID+"</td>"
+FirstObj.UserID+"</td>");
"</td>");
Response.Write("<td>"
Response.Write("<td>"+FirstObj.Email+
"<td>"+FirstObj.Email+"</td>"
+FirstObj.Email+"</td>");
"</td>");
Response.Write("<td>"
Response.Write("<td>"+FirstObj.Status+
"<td>"+FirstObj.Status+"</td></tr>"
+FirstObj.Status+"</td></tr>");
"</td></tr>");
Response.Write("</table>"
Response.Write("</table>");
"</table>");
Response.Write("<ol>"
Response.Write("<ol>");
"<ol>");
Response.Write("<b>Account
Response.Write("<b>Account List Information</b></br>");
Information</b></br>");
foreach (Accounts AccouObj in AccountList)
{
Response.Write("<li>Full
Response.Write("<li>Full Name(First and Last): "+AccouObj.First
"+AccouObj.First + "--
"+AccouObj.Last+"</li>"
+AccouObj.Last+"</li>");
"</li>");
Response.Write("<ul>"
Response.Write("<ul>");
"<ul>");
Response.Write("<li>User
Response.Write("<li>User ID: "+AccouObj.UserID+
"+AccouObj.UserID+"</li>"
+AccouObj.UserID+"</li>");
"</li>");
Response.Write("<li>Email:
Response.Write("<li>Email: "+AccouObj.Email+
"+AccouObj.Email+"</li>"
+AccouObj.Email+"</li>");
"</li>");
Response.Write("<li>Status:
Response.Write("<li>Status: "+AccouObj.Status+
"+AccouObj.Status+"</li>"
+AccouObj.Status+"</li>");
"</li>");
Response.Write("</ul>"
Response.Write("</ul>");
"</ul>");
}
Response.Write("</ol>"
Response.Write("</ol>");
"</ol>");
}
}
</script
</script>
script>

Page 5 of 5 5

You might also like