20.ASPNET-Lab Exercises and Solutions
20.ASPNET-Lab Exercises and Solutions
Excercise 1
The different options for the list box must be ASP-XML, DotNET, JavaPro and Unix,C,C++. When the
Submit Form button is clicked after entering the data, a message as seen in the last line of the above
figure must be displayed.
Excercise 2
Write a program to display three images in a line. When any one of the images is clicked, it must be
displayed below. On clicking the displayed image it must be cleared. The screen must look as in the
figure given below:
Lab
2
Excercise 1
Write a simple ASP.NET program to display the following Web Controls:
A button with text “click me”. The button control must be in the center of the form.
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 1
A label with a text hello
A checkbox.
The form name must be Web Controls
Excercise 2
Write a program to display “Welcome To Radiant” in the form when the “click” button is clicked. The
form title must be ASP.NET.
Excercise 3
Write a program that displays a button in green color and it should change into yellow when the mouse
moves over it.
Lab
3
Excercise 1
Write a program containing the following controls:
A ListBox
A Button
An Image
A Label
The listbox is used to list items available in a store. When the user clicks on an item in the listbox, its
image is displayed in the image control. When the user clicks the button, the cost of the selected item is
displayed in the control.
Excercise 2
Excercise 3
Excercise 4
Write a JavaScript code that displays two advertisements alternately. When the user clicks on one of
the advertisements, he/she is redirected to “www.amazon.com”, and the other advertisement
redirects the user to “www.fabmart.com”. The weightage of the amazon advertisement is 50 and that
of the other one is 40. The advertisement should be centered horizontally and should cover 60% of the
width of the screen. Its height should be 80 units. The width of the border should be 5 units.
Lab 4
Excercise 1
Write a program to get a user input such as the boiling point of water and test it to the appropriate
value using CompareValidator.
Excercise 2
Write a program that uses a textbox for a user input name and validate it for RequiredField Validation.
Excercise 3
Write a prgoram that gets user input such as the user name, mode of payment, appropriate credit card.
After the user enters the appropriate values the Validation button validates the values entered.
Lab
5
Excercise 1
Create a Form that receives the user name, address, date, nationality, country preferred for working and
skill sets from the user and stores the user name in the client using cookies. The country preferred data
should appear in a dropdownlist whereas, others should be entered in a textbox. Validate all the
controls. The Form is named “formexp.aspx”. The date should appear between “1/1/1900” and
“1/1/2090”.
Lab
6
Excercise 1
Create an application that illustrates how a content can be buffered.
ASP.NET
Lab 7
Excercise 1
Create a Global.asax file with Application variables cont, color1 and gotohp. Create a Session variable
called cont1. Initialize cont as 0 and assign any color to color1. For the variable gotohp, give a
hyperlink to any Website. Use the variables in a Web Form. Try these with the lock and unlock
methods.
Lab
8
Excercise 1
3. Change the candidate name from ‘S.Raman’ to ‘R.Krishnan’ in the first record in CANDIDATE
table.
4. Drop the table CANDIDATE.
5. Create table Employee with the following columns and datatypes.
Dept Numeric
Name Varchar(20)
Doj Datetime
Sal Float
Desgin Varchar(20)
Lab
9
Excercise 1
Write a program to connect to the master database in SQL Server, in the Page_Load event. When the
connection is established, the message “Connection has been established” should be displayed in a
label in the form.
Excercise 2
Write a program to create a table emp in the master database with the following fields:
Excercise 3
Write a program that updates the ename field of the emp table with the given name, where eno=102.
Excercise 4
Write a program to select those rows from the emp table whose eno >=100.
ASP.NET
Lab 10
Excercise 1
Select the names of the employees from the emps table. Retrieve the result in a DataSet and display it
in a CheckBoxList.
Excercise 2
Select names from the emps table. Retrieve the result in a DataSet. Bind the DataSet to a
RadioButtonList and display the result in three diferent forms as follows:
i) The RepeatDirection property of the RadioButtonList is set to horizontal and its RepeatLayout
property is set to Table.
ii) The RepeatDirection property of the RadioButtonList is set to Vertical and its RepeatLayout
property is set to Table.
iii) The RepeatLayout property of the RadioButtonList is set to flow.
Excercise 3
Create a Table, which displays two columns and three rows. The first row displays eno, the second
displays ename and the third displays esal, all of these being retrieved from the emps table. Each of
the above is displayed as a drop-down list, containing all the values of the corresponding column in the
table.
Lab 11
Excercise 1
Write a program that binds the properties ID, Name, Price and Qty of a page to the following values:
ID: 10
Name: Wheat
Price: 14.25
Qty: 1000
Excercise 2
Create a RadioButtonList that displays the names of some flowers in two columns. Bind a label to the
RadioButtonList so that when the user selects an option from the list and clicks on a button, the label
displays the flower selected by the user.
Excercise 3
Bind a CheckBoxList to the pname field of the product table in the master database so that all the name
of the product are displayed as a series of checkboxes.
Excercise 1
Write a program to display the records from the database as shown in the figure:
Note: Create a table Customer with records shown in the above figure.
Excercise 2
Write a program to implement the sorting feature in the customer table as shown in the figure:
Note: Create a table Customer with records shown in the above figure.
Excercise 3
Write a program to implement paging feature in the customer table as shown in the figure below.
Note: Create a table Customer with records shown in the above figure.
Lab 13
Excercise 1
ASP.NET
ADO.NET
C#
It also contains a textbox in which the user has to enter a name and a textarea in which the user has to
enter his comments. When the Submit is clicked, the output should display the name entered in the
textbox and the user-selection from the listbox. All the above should be displayed with the tracing for
the page being enabled.
Excercise 2
Write a Web application that generates the “IndexOutOfRange” exception when a button is clicked.
Instead of displaying the above exception, it redirects the user to a custom error page. All the above
should be done with the trace for the page being enabled.
Excercise 3
Write a Web application that retrieves the names of the employees from the emp table. The trace for the
page should be enabled.
Lab 14
Excercise 1
Create a user control that contains a list of colors. Add a button to the Web Form which when clicked
changes the color of the Form to the color selected from the list.
Excercise 2
Create a user control that displays the current date and time. Include it in a Web Form and refresh it
each time a button is clicked.
Excercise 3
Create a user control that receives the user name and password from the user and validates them. If the
user name is “Radiant” and the password is “asp.net” then the user is authorized, otherwise not.
Lab 15
Excercise 1
Create a component that receives two numbers from the user through a Web Form, and based on the
user’s selection it adds or subtracts the two numbers and returns the result to the Web Form. The
result should be displayed in the Web Form.
Excercise 2
Create two components, the first of which is an abstract class containing an abstract method. The
second component should implement the first component’s abstract class and returns a string from the
method. Display the result in a Web Form.
Excercise 3
Create a component that contains an array of 100 integers and a corresponding indexer. From a Web
page, assign values to some of its elements. Then the Web Form should display the first 10 elements of
the indexer.
<body>
<h5><font face=”Arial”>Courseware Feedback Form</font></h5>
<form runat=server>
<p>Student name:<input id=”name” type=text size=40 runat=”server”><br>
<p>Technical Coverage:</p>
<input type=”radio” id=”Excellent”
name=”Mode2" runat=”server”/>Excellent<br>
<input type=”radio” id=”Good” name=”Mode2" runat=”server”/>Good<br>
<input type=”radio” id=”Average” name=”Mode2" runat=”server”/>Average<br>
<input type=”radio” id=”Poor” name=”Mode2" runat=”server”/>Poor
<p>Suggestions:</p>
<textarea id=”TextArea1" runat=”server” cols=40 rows=2 />
<input type=button id=”Button1" value=”Submit
Form” OnServerClick=”Button1_Click”
runat=”server”>
<p><span id=”Message” runat=”server”/>
</form>
Lab Solutions
</body>
</html>
Exercise : 2
<head>
<script language=”C#” runat=”server”>
</script>
</head>
<form runat=”server”>
<p>Click on any of the first three images to display it at the bottom
<p>Click on the bottom image to clear it</p>
<p><input type=image id=”Image1"
src=”d:/images/circle.bmp” OnServerClick=”Button1_Click”
runat=”server”>
<input type=image id=”Image2"
src=”d:/images/square.bmp”
OnServerClick=”Button2_Click” runat=”server”>
<input type=image id=”Image3"
src=”d:/images/triangle.bmp”
OnServerClick=”Button3_Click” runat=”server”> </p>
<hr>
<input type=image id=”Image4" src=””
OnServerClick=”Button4_Click” runat=”server”>
</form>
Exercise : 1
<html>
<head>
<title> Web Controls </title>
<center>
<asp:button id=”b1" text=”Click me” runat=”server” />
</asp:button>
</center>
<asp:label id=”L1" text=”Hello” runat=”server” />
</asp:label>
<asp:checkbox id=”C1" runat=server/>
</asp:checkbox>
</head>
</html>
Exercise : 2
<html>
<head>
<title> ASP.NET </title>
<script language=”c#” runat=”server”>
void button1_Click(Object Sender,EventArgs E)
{
s1.InnerHtml=”Welcome To Radiant”;
}
</script>
</head>
<center>
<asp:button id=”b1" OnClick=”button1_Click” text=”Click me” runat=”server”
/>
</asp:button>
</center>
<span id=s1 runat=”server” />
</form>
</body>
</html>
Exercise : 3
<html>
<head>
<title> ASP.NET </title>
</head>
<form id=f1 runat=”server”>
<body>
<font color=”green”>
<span id=s1 runat=”server” />
</font>
<br><br>
<h3> Move The Mouse Over Me and oy </h3>
<asp:button id=”Button2" OnServerClick=”Button2_Click” text=”Click me
too! “
style=”font: 8pt
verdana;background-color:lightgreen;border-color:black;height=30;width:100"
onmouseover=”this.style.backgroundColor=’yellow’”
onmouseout=”this.style.backgroundColor=’lightgreen’”
runat=”server”/>
</form>
</body>
</html>
Lab – 3
Exercise : 1
<html>
<head>
<Script language=”c#” runat=”Server”>
<body>
<form runat=”server”>
<asp:label id = “label1” Text=”Choose one of the items
below” Font-Name=”Verdana” Font-Size=”18pt” runat=”server”
/>
<br><br>
<asp:listbox id=”Store” AutoPostBack=”True”
width=”200" runat=”server”
onSelectedIndexChanged=”display”>
<asp:listitem>Cola</asp:listitem>
<asp:listitem>Red Pop</asp:listitem>
<asp:listitem>Lime</asp:listitem>
<asp:listitem>Purple Rain</asp:listitem>
</asp:listbox>
<asp:Image ID=”Img” ImageUrl=”” AlternateText=”” runat=”server” />
<br><br>
<asp:button id=”Find” text=”Find Cost”
OnClick=”Calculate” runat=”server”/>
<br><br>
<asp:textbox id=”Cost” text=”0" width=350 runat=”server”/>
</form>
</body>
</html>
Exercise : 2
<html>
<head>
<Script language=”c#” runat=”Server”>
void Calculate(Object sender,EventArgs
e)
{
if (Store.SelectedIndex > -1){
int i = Store.SelectedIndex;
Cost.Text = “You have chosen “ + Store.SelectedItem.Value + “
and its cost is Rs.”;
if (i==0)
Cost.Text +=
“30”; else if (i==1)
Cost.Text +=
“32”; else if (i ==
2)
Cost.Text +=
“28”; else
Cost.Text += “26”;
}
}
void display(Object sender, EventArgs e)
{
int i = Store.SelectedIndex;
if (i==0)
{
Img.ImageUrl = “Cola.gif”;
Img.AlternateText = “Cola”;
}
else if (i==1)
{
Img.ImageUrl = “Red_pop.gif”;
Img.AlternateText = “Red Pop”;
}
else if (i == 2)
{
Img.ImageUrl = “Lime.gif”;
Img.AlternateText = “Lime”;
}
else
{
Img.ImageUrl = “Purple_Rain.gif”;
Img.AlternateText = “Purple
Rain”;
}
}
void add(Object sender, EventArgs e)
{
int tot=0;
int qty =
System.Int32.Parse(qtyText.Text);
switch(Store.SelectedIndex)
{
case 0: tot = qty *
30; break;
case 1: tot = qty *
32; break;
case 2: tot = qty *
28; break;
case 3: tot = qty *
26; break;
}
total.Text = “You have to pay a total of Rs.” + tot;
}
</Script>
</head>
<body>
<form runat=”server”>
<asp:label id = “label1” Text=”Following are the items available with
us” Font-Name=”Verdana” Font-Size=”18pt”
runat=”server” />
<br><br>
<asp:listbox id=”Store” AutoPostBack=”True” width=”200" runat=”server”
onSelectedIndexChanged=”display”>
<asp:listitem>Cola</asp:listitem>
<asp:listitem>Red Pop</asp:listitem>
<asp:listitem>Lime</asp:listitem>
<asp:listitem>Purple Rain</asp:listitem>
</asp:listbox>
Exercise : 3
Exercise : 4
The ASPX file:
<html>
<body>
<Center>
<asp:AdRotator Width = “60%” Height=80 id=a1
AdvertisementFile=”ads.xml” BorderWidth=5 runat=server
/>
</Center>
</body>
</html>
Lab – 4
Exercise : 1
<html>
<body>
<form runat=”server”>
<asp:label id=”label” text=”Enter the Boiling point of water :
“ runat=”server” />
<asp:textbox id=”text1" text=” “ runat=”server”/>
<asp:comparevalidator id=”compboilpt”
controltovalidate=”text1" Type=”Integer”
ValueToCompare=100 Operator=”Equal” display=”static” errormessage=”Please
enter correct value” runat=”server”>
</asp:comparevalidator>
<asp:ValidationSummary id=”sumErrors”
runat=”server” showSummary = true
displayMode = “BulletList” />
<br>
<asp:button id=bt1 runat=”server” text=”click”/>
</form>
</body>
</html>
Lab Solutions
Exercise : 2
<html>
<body>
<h3>RequiredFieldValidation</h3>
<form runat=server>
Name: <asp:Textbox id=”txtName” runat=”server”></asp:Textbox>
<asp:button id=”Button1" runat=”server” text=”Validate” />
<p>
<asp:RequiredFieldValidator id=”RequiredFieldValidator1"
runat=”server” ControlToValidate=”txtName”
ErrorMessage=”Name is a required
field” ForeColor=”Red”>
</asp:RequiredFieldValidator>
</form>
</body>
</html>
Exercise : 3
<tr>
<td> <asp:label id=”label1" runat=”server” style=color:”pink”/>
</td>
</tr>
</table>
</form>
</html>
Lab
Exercise : 1
5
<html>
<title> Using Request Object </title>
<script language=”c#”
runat=”server”> void
btnclick(object s,EventArgs
e)
{
if (Page.IsValid==true )
{
result.Text=”Thanks for Registering.Soon u will be
Contacted”; HttpCookie Cookie;
Cookie = new HttpCookie(“cookname”);
Cookie.Values.Add(“uname “,Request.Form[“u
name”]);
Response.AppendCookie(Cookie);
Cookie = Request.Cookies[“cookname”];
Response.Write (Cookie.Value + “ has visited the
site .”);
}
el
se
{ result.Text=”Sorry you have to fill these fields”;
}
}
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 23
ASP.NET
<
/
s
c
r
i
p
t
>
<
f
o
r
m
r
u
n
a
t
=
”
s
e
r
v
e
r
”
m
e
t
h
o
d
=
”
P
o
s
t
”
a
c
t
i
o
n
=
”
f
o
r
m
e
x
p
.
a
s
p
x
”
>
Lab
6
Exercise : 1
Exercise : 1
Global.asax:
Lab
8
Exercise : 1
Lab 9
Exercise : 1
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SQL” %>
<html>
<title> Connecting to Pubs database </title>
<script language=”C#”
runat=”server”> SQLConnection
conn;
void Page_Load(Object Src, EventArgs E)
{
conn = new SQLConnection(
“server=localhost;uid=sa;pwd=;database=master”);
conn.Open();
lbl.Text = “Connection has been
established”; conn.Close();
}
</script>
<body>
<form>
<asp:label id = “lbl” runat=”server” />
</form>
</body>
</html>
Exercise : 2
<html>
<title> Creating the table EMP</title>
<script language=”C#”
runat=”server”> SQLConnection conn;
protected void Page_Load(Object Src, EventArgs E)
{
conn = new SQLConnection
(“server=localhost;uid=sa;pwd=;database=master”);
}
public void CreTab(Object sender, EventArgs E)
{
String upd = “create table emp(eno integer, ename
varchar(20), salary float)”;
SQLCommand com = new
SQLCommand(upd,conn);
com.ActiveConnection.Open();
try
{
com.ExecuteNonQuery();
lb.Text = “The table EMP has been created”;
}
catch (SQLException e)
{
lb.Text = “Error while creating the table”;
}
com.ActiveConnection.Close();
}
</script>
<body>
<form runat=”server”>
<asp:button OnClick=”CreTab” Text=”Create
Table” runat=”server”/><br><br>
<asp:label id=”lb” runat=”server” />
</form>
</body>
</html>
Exercise : 3
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SQL” %>
<html>
<title> Updating a record </title>
<script language=”C#”
(“server=localhost;uid=sa;pwd=;database=master”);
}
public void UpdEmp(Object sender, EventArgs E)
{
String upd = “update emp set ename= ‘“ + ename.Text + “‘ where
eno=102";
SQLCommand com = new
SQLCommand(upd,conn);
com.ActiveConnection.Open();
try
{
com.ExecuteNonQuery();
lb.Text = “The record has been modified”;
}
catch (SQLException e)
{
lb.Text = “Error while updating”;
}
com.ActiveConnection.Close();
}
</script>
<body>
<form runat=”server”>
Exercise : 4
<html>
<title> Records from Emp </title>
<script language=”C#” runat=”server”>
SQLConnection conn;
protected void Page_Load(Object Src, EventArgs E)
{
conn = new SQLConnection(
“server=sangeetha;uid=sa;pwd=;database=master”);
SQLCommand com = new SQLCommand(“select distinct * from emp
where eno>=100", conn);
conn.Open();
SQLDataReader dr;
com.Execute(out
dr);
Response.Write(“<Table width=250 border=1
cellpadding=5>”); Response.Write(“<TR>”);
Response.Write(“<TD>”);
Response.Write(“<B>ID </B>”);
Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(“<B>Name </B>”);
Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(“<B>Salary </B>”);
Response.Write(“</TD>”);
Response.Write(“</TR>”);
while (dr.Read())
{
Response.Write(“<TR>”);
Response.Write(“<TD>”);
Response.Write(dr[“eno”].ToString() + “
“); Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(dr[“ename”].ToString() + “
“); Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(dr[“sal”].ToString() + “ “);
Response.Write(“</TD>”);
Response.Write(“</TR>”);
}
conn.Close();
}
</script>
</html>
Lab 10
Lab Solutions
Exercise : 1
<script language=”C#”
runat=”server”> void
Page_Load(Object o, EventArgs e)
{
DataSet ds;
SQLConnection con;
SQLDataSetCommand
com; string strconn;
string strSQL;
strconn=”server=localhost;uid=sa;pwd=;database=model”;
con = new SQLConnection(strconn);
</body>
</html>
st.DataSource=ds.Tables[“emps”].DefaultView;
st.DataBind();
st2.DataSource=ds.Tables[“emps”].DefaultView;
st2.DataBind();
st3.DataSource=ds.Tables[“emps”].DefaultView;
st3.DataBind();
}
</script>
<html><head>
<title>Radio Buttons from States</title>
</head>
<body bgcolor=”#FFFFFF”>
<h3><font face=”Verdana”>State(s) to Query</font></h3>
<hr>
repeatcolumns 5, repeatdirection horizontal, repeatlayout table<br>
<ASP:radiobuttonList
repeatcolumns=”5" repeatdirection=”horizontal” repeatlayout=”table”
id=”st” datatextfield=”ename” DataValueField=”ename”
runat=”server”/>
<br>
<hr>
repeatcolumns 5, repeatdirection vertical, repeatlayout table<br>
<ASP:radiobuttonList
repeatcolumns=”5" repeatdirection=”vertical” repeatlayout=”table”
id=”st2" datatextfield=”ename” DataValueField=”ename”
runat=”server”/>
<hr>
repeatlayout flow<br>
<ASP:radiobuttonList
repeatlayout=”flow”
id=”st3" datatextfield=”ename” DataValueField=”ename” runat=”server”/>
<hr>
</body>
</html>
Lab Solutions
Exercise : 3
strconn=”server=localhost;uid=sa;pwd=;database=model”;
con = new SQLConnection(strconn);
}
</script>
<html><head>
<title>Grid of New York Data</title>
</head>
<body bgcolor=”#FFFFFF”>
<h3><font face=”Verdana”>No, Name, Salary Lists of emps Table</font></h3>
<asp:TableRow>
<asp:TableCell>Name</asp:TableCell>
<asp:TableCell><ASP:DropDownList id=”st”
datatextfield=”ename” DataValueField=”ename”
runat=”server”/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Salary</asp:TableCell>
<asp:TableCell><ASP:DropDownList id=”zp”
datatextfield=”esal” DataValueField=”esal”
runat=”server”/></asp:TableCell>
</asp:TableRow>
</asp:Table>
</body>
</html>
Lab 11
Exercise : 1
<html>
<head>
<title> Details of products </title>
<script language=”C#” runat=”server”>
void Page_Load(Object sender, EventArgs e)
{ Page.DataBind();
}
int
ID{ get
{ return 10;
}
}
string Name{
get {
return “Wheat”;
}
}
float
Price{
get { return 14.25f;
}
}
int Qty{
get
{ return 1000;
}
}
</script>
</head>
<body>
<form runat=server>
Product ID: <b><%# ID
%></b><br> Product Name: <b><%# Name
%></b><br>
Price: <b><%# Price %></b><br>
Quantity: <b><%# Qty %></b>
</form>
</body>
</html>
Exercise : 2
<html>
<head>
<title> Binding to a label </title>
<script language=”C#” runat=”server”>
void Btn_Click(Object sender, EventArgs e)
{ Page.DataBind();
}
</script>
</head>
<body>
<form runat=server>
<asp:RadioButtonList id=”Flower” repeatcolumns=2 runat=”server” size=3>
<asp:ListItem>Jasmine</asp:ListItem>
<asp:ListItem>Rose</asp:ListItem>
<asp:ListItem>Lotus</asp:ListItem>
<asp:ListItem>Lily</asp:ListItem>
<asp:ListItem>Daisy</asp:ListItem>
<asp:ListItem>Dahlia</asp:ListItem>
</asp:RadioButtonList>
<br><br>
<asp:button Text=”Submit” OnClick=”Btn_Click” runat=server/>
<br><br>
Your favourite flower is: <asp:label text=’<%# Flower.SelectedItem.Text %>’
runat=server/>
</form>
</body>
</html>
Exercise : 3
<script language=”C#”
runat=”server”> SQLConnection conn;
string connStr, query;
connStr=”server=localhost;uid=sa;database=master”;
conn = new SQLConnection(connStr);
<body>
<form runat=server>
<asp:Label id=”lbl” text=”Following is the list of
available products: “ runat=”server” />
<br><br>
<asp:CheckBoxList id=”prods” runat=”server” />
</form>
</body>
</html>
Lab 12
Exercise : 1
<head>
<script language=”c#” runat=”server” >
String conn;
ADODataSetCommand mycommand=new
ADODataSetCommand(“select customerid,customername from
customer”,conn);
</script>
</script>
</head>
<form runat=”server”>
<h4> Sorting Datagrid Control </h4>
<asp:Datagrid id=”DataGrid1" runat=”server” />
</form>
</body>
</html>
Exercise : 2
if (!IsPostBack)
BindGrid(“CustomerID”);
}
void dbsort(object src,DataGridSortCommandEventArgs e)
{
BindGrid(e.SortField);
}
void BindGrid(String sortfield)
{
Exercise : 3
</script>
<form runat=”server”>
<h3> Paging Feature </h3>
<br>
<ASP:DataGrid id=”dg” runat=”server” AllowPaging=”True”
PageSize=”3" PageCount=”1"
PagerStyle-Mode=”NumericPages”
PagerStyle-HorizontalAlign=”Right”
OnPageIndexChanged=”changePage”
/>
</form>
Lab 13
Exercise : 1
<html>
<head><title>Tracing Events</title></head>
<body>
<% Trace.Warn( “user”, “page mid rendering event!” ); %>
<form runat=”server”>
<asp:label id=”myLabel” runat=”server”/>
<p>
<b>Enter Your Name:</b>
<br>
<asp:textbox id=”yourName” runat=”Server” />
<p>
<b>Pick Your Favorite technology:</b>
<br>
<asp:dropdownlist id=”favTech” runat=”server”>
<asp:listitem>ASP.NET</asp:listitem>
<asp:listitem>ADO.NET</asp:listitem>
<asp:listitem>C#</asp:listitem>
</asp:dropdownlist>
<p>
<b> Comments:</b>
<br>
<asp:textbox id=”comments” textmode=”multiline” cols=”20"
rows=”5" runat=”Server” />
<p>
<asp:button text=”Submit!” onClick=”test” runat=”server” />
</form>
</body>
</html>
Exercise : 2
<form runat=”server”>
<asp:button id=”button1"
onclick=”button1_click” text=”click me”
runat=”server” />
</form>
</html>
Exercise : 3
<html>
<script language=”C#” runat=”server”>
void Page_Load(Object Src, EventArgs E)
{
if(Trace.IsEnabled)
{
SQLConnection con = new
SQLConnection(“server=localhost;uid=sa;pwd=”);
SQLDataSetCommand com = new SQLDataSetCommand(“select
ename from emptab”, con);
DataSet ds = new DataSet();
com.FillDataSet(ds, “emptab”);
d.DataSource=ds.Tables[“emptab”].DefaultView;
d.DataBind();
}
}
</script>
<body>
<ASP:DataGrid id=”d”
runat=”server” Width=”100"
BackColor=”#ccccff”
BorderColor=”black”
CellPadding=3
CellSpacing=”0"
Font-Name=”Verdana”
Font-Size=”8pt”
HeaderStyle-BackColor=”#aaaadd”
/>
</body>
</html>
Lab 14
Exercise : 1
<script language=”C#” runat=”server”>
void Page_Load(Object sender, EventArgs E)
{ if(Page.IsPostBack)
{
display.Text=”You have selected the color: “
+ col.SelectedItem.Text ;
}
}
public String Color
{ get {
return col.SelectedItem.Text;
}
}
</script>
Colors: <asp:ListBox id=”col” runat=”server” >
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Gray</asp:ListItem>
</asp:ListBox>
<br><br>
<b> <asp:Label id=”display” runat=”server” /> </b>
Exercise : 3
</script>
<body>
<form id=”frm” runat=”server”>
<User:Login id=”log” runat=”server”/>
</form>
</body>
</html>
Lab 15
Exercise : 1
//calcomp.cs
using System;
namespace
calcomp
{
public class cal
{
public int add(String t1,String t2)
{
int
a=Int32.Parse(t1);
int
b=Int32.Parse(t2);
return a+b;
}
public int sub(String t1,String t2)
{
int
a=Int32.Parse(t1);
int
b=Int32.Parse(t2);
return a-b;
}
}
}
//calapp.aspx
<html>
<script language=”C#” runat=”server”>
void button_add(Object Src, EventArgs E)
{
cal o1=new cal();
int c=o1.add(t1.Text,t2.Text);
Response.Write(“The value of a+b is “+c.ToString());
}
void button_sub(Object Src, EventArgs E)
{
cal o1=new cal();
int c=o1.sub(t1.Text,t2.Text);
Response.Write(“The value of a-b is “+c.ToString());
}
</script>
<body>
<form runat=server>
<h5>Enter the Value of a: </h5>
<asp:textbox id=t1 Text=”0" runat=server/>
<br>
<h5>Enter the Value of b: </h5>
<asp:textbox id=t2 Text=”0" runat=server/>
<p>
<asp:Button id=b1 text=”Add” OnClick=button_add runat=server/>
<asp:Button id=b2 text=”Subtract” OnClick=button_sub runat=server/>
</form>
</html>
Exercise : 2
//abscomp.cs
using System;
namespace abscomp
{
abstract public class Absclass
{
abstract public String method();
}
}
//dercomp
using System;
using abscomp;
namespace dercomp
{
public class derived:Absclass
{
public override String method()
{
return (“Abstract Class”);
}
}
}
//absapp.aspx
<%@ Import Namespace=”dercomp” %>
<html>
<script language=”C#” runat=”server”>
public void Page_Load(Object sender, EventArgs E)
{
derived d1=new derived();
String s=d1.method();
Response.Write(s.ToString());
}
</script>
</html>
Exercise : 3
//indcomp.cs
namespace indcomp
{
public class IndexerClass
{
int [] a = new int[100];
public int this [int
index]
{
get
{
if (index < 0 || index >=
100) return 0;
else
return a[index];
}
set
{
if (!(index < 0 || index >= 100))
a[index] = value;
}
}
}
}
//indapp.aspx
<%@ Import Namespace=”indcomp” %>
<html>
<script language=”C#” runat=”server”>
public void Page_Load(Object sender, EventArgs E)
{
IndexerClass b = new
IndexerClass(); b[2] = 30;
b[6] = 35;
b[4]=40;
b[7]=10;
for (int i=0; i<=10; i++)
{
Response.Write(“Indexer Element at “+ i+ “is “ +
b[i]); Response.Write(“<br>”);
}
}
</script>
</html>