0% found this document useful (0 votes)
5 views50 pages

ASP NET Lab 1programs

The document outlines a series of ASP.NET web applications demonstrating various web controls and functionalities, including exposure of web applications, HTML controls, server controls, and data binding. Each program is presented with its corresponding ASPX and code-behind files, showcasing features like user input handling, file uploads, and database operations such as insert, update, and delete. The document serves as a comprehensive guide for building web applications using ASP.NET with practical examples.

Uploaded by

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

ASP NET Lab 1programs

The document outlines a series of ASP.NET web applications demonstrating various web controls and functionalities, including exposure of web applications, HTML controls, server controls, and data binding. Each program is presented with its corresponding ASPX and code-behind files, showcasing features like user input handling, file uploads, and database operations such as insert, update, and delete. The document serves as a comprehensive guide for building web applications using ASP.NET with practical examples.

Uploaded by

j.gokul27022006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Exposure of Web Applications and Tools

[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program1" %>
<!DOCTYPE html>

<html>

<head>

<title>Program 1 - Exposure of Web Applications</title>


</head>

<body>

<form id="form1" runat="server">

<h2>Welcome to [Link] Web Application</h2>

<asp:Label ID="lblInfo" runat="server" Font-Size="Large"></asp:Label>

</form>

</body>
</html>

[Link]:
using System;
public partial class Program1 : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
[Link] = "This web application is running on: " + [Link]
+""+
[Link] + "<br />Server software: [Link] using Visual Studio
2019<br
/>" +
"Tools used: Visual Studio, .NET Framework, IIS
Express.";
}
}
[Link] of Web Applications and Tools
Output:
2. Implement HTML Controls
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program2" %>
<!DOCTYPE html>
<html>
<head><title>Program 2 - HTML
Controls</title></head>
<body>
<form id="form1" runat="server">

<label for="name">Enter your name:</label>

<input type="text" name="name" />

<br /><br />

<input type="submit" value="Submit" />


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

[Link]:
using System;
public partial class Program2 :
[Link]

{
protected void Page_Load(object sender,
EventArgs e)

if (IsPostBack)

string name = [Link]["name"]; [Link]("Hello, "


+ name);
}

}
}
[Link] HTML Controls
Output:
3. Implement Server Controls
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program3" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 3</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtInput" runat="server" Placeholder="Enter Text"></asp:TextBox><br
/><br />
<asp:Button ID="btnDisplay" runat="server" Text="Display" OnClick="btnDisplay_Click"
/><br /><br />
<asp:Label ID="lblOutput" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

[Link]:
using System;

public partial class Program3 : [Link]


{
protected void btnDisplay_Click(object sender,
EventArgs e)
{
[Link] = "You entered: " + [Link];
}
}
3. Implement Server Controls

Output:
4. Web Application Using Web Controls
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program4" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 4</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlColors" runat="server">
<asp:ListItem Text="Red"
Value="Red"></asp:ListItem>
<asp:ListItem Text="Green"
Value="Green"></asp:ListItem>
<asp:ListItem Text="Blue"
Value="Blue"></asp:ListItem>
</asp:DropDownList><br /><br />
<asp:CheckBox ID="chkBold" runat="server"
Text="Bold" />
<br/ > <br />
<asp:RadioButtonList ID="rblSize" runat="server">
<asp:ListItem Text="10" Value="10"></asp:ListItem>
<asp:ListItem Text="14" Value="14"></asp:ListItem>
<asp:ListItem Text="18" Value="18"></asp:ListItem>
</asp:RadioButtonList><br /><br />
<asp:Button ID="btnStyle" runat="server" Text="Apply Style"
OnClick="btnStyle_Click" /><br /><br />
<asp:Label ID="lblStyledText" runat="server" Text="Sample
Text"></asp:Label>
</div>
</form>
</body>
</html>
[Link]:
using System;
public partial class Program4 : [Link]
{
protected void btnStyle_Click(object sender, EventArgs e)
{
[Link] =
[Link]([Link]);
[Link] = [Link]; [Link] =
[Link](Convert.ToInt32([Link]));
}
}
4. Web Application Using Web Controls

Output:
5. Web Application Using List Controls
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program5" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 5</title> </head> <body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="lstFruits" runat="server"
SelectionMode="Multiple">
<asp:ListItem>Apple</asp:ListItem>
<asp:ListItem>Banana</asp:ListItem>
<asp:ListItem>Cherry</asp:ListItem>
</asp:ListBox><br /><br />
<asp:CheckBoxList ID="cblHobbies" runat="server">
<asp:ListItem>Reading</asp:ListItem>
<asp:ListItem>Traveling</asp:ListItem>
<asp:ListItem>Swimming</asp:ListItem>
</asp:CheckBoxList><br /><br />
<asp:Button ID="btnShowSelections" runat="server" Text="Show
Selections"
OnClick="btnShowSelections_Click" /><br /><br />
<asp:Label ID="lblSelections" runat="server"></asp:Label>
</div>
</form> </body> </html>
[Link]:
using System; [Link];
public partial class Program5 : [Link]
{
protected void btnShowSelections_Click(object sender,
EventArgs e)
{
StringBuilder sb = new StringBuilder(); [Link]("Fruits:
");
foreach ([Link] li in
[Link])
{
if ([Link]) [Link]([Link] + ", );
}
[Link](" | Hobbies: ");
foreach ([Link] li in
[Link])
{
if ([Link])
[Link]([Link] + ", ");
}
[Link] = [Link]();
}
}
5. Web Application Using List Controls

Output:
6. Web Page Design Using Rich Controls and Validation Controls and File Handling

[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program6" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 6</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar><br /
><br />
Select Date: <asp:TextBox ID="txtDate" runat="server"
ReadOnly="True"></asp:TextBox><br /><br />
<asp:RequiredFieldValidatorControlToValidate="fuFile"
ErrorMessage="Select a file"
runat="server"></asp:RequiredFieldValidator><br /><br />
<asp:FileUpload ID="fuFile" runat="server" /><br /><br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click"
/><br /><br />
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

[Link]:

using System;

public partial class Program6 : [Link]


{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
[Link] = [Link]();
}
}
protected void Calendar1_SelectionChanged(object sender,
EventArgs e)
{
[Link] = [Link]();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if ([Link])
{
string path = [Link]("~/Uploads/") +
[Link];
[Link](path);
" + path; [Link] = "Date: " + [Link] + " | File
saved at:
}
else
{
[Link] = "Please select a
file.";
}
}
}
6. Web Page Design Using Rich Controls and Validation Controls and File
Handling

Output:
7. Web Application Using Data Controls
[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>

<html xmlns="[Link]
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" AutoGenerateColumns="False"
DataKeyNames="StudentId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="StudentId" HeaderText="StudentId"
InsertVisible="False"
ReadOnly="True" SortExpression="StudentId" />
<asp:BoundField DataField="SName" HeaderText="SName"
SortExpression="SName"
/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:SchoolDBConnectionString %>"
SelectCommand="SELECT * FROM
[Student]"></asp:SqlDataSource></div>
</form>
</body>
</html>
7. Web Application Using Data Controls

Output:
8. Data Binding with Web Controls

[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program8" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 8</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlStudents" runat="server"
DataSourceID="SqlDataSource1"
DataTextField="Name" DataValueField="StudentID"></asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"


ConnectionString="<%$
ConnectionStrings:SchoolDBConnectionString %>"

SelectCommand="SELECT StudentID, Name FROM Students"></asp:SqlDataSource>


</div>
</form>
</body>
</html>
8. Data Binding with Web Controls

Output:
DropDownList populated with student names from database; selecting
an item sets
SelectedValue to StudentID.
9. Data Binding with Data Controls

[Link]:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="[Link]"
Inherits="Program9" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 9</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="True"

DataKeyNames="StudentID"
DataSourceID="SqlDataSource1"></asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:SchoolDBConnectionString %>" SelectCommand="SELECT
StudentID,
Name, Age FROM Students WHERE StudentID=1"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
9. Data Binding with Data Controls

Output:
DetailsView displays the record of student with StudentID = 1.
10. Database Application to Perform Insert, Update, Delete Operations

[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]"
Inherits="Program10" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 10 - Insert, Update, Delete with Auto ID</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Student ID:<br />

<asp:TextBox ID="txtID" runat="server" ReadOnly="true" /><br /><br/>


Name:<br />
<asp:TextBox ID="txtName10" runat="server" /><br /><br />
Age:<br />
<asp:TextBox ID="txtAge10" runat="server" /><br /><br />
<asp:Button ID="btnInsert" runat="server" Text="Insert"
OnClick="btnInsert_Click" />
<asp:Button ID="btnUpdate" runat="server" Text="Update"
OnClick="btnUpdate_Click" />
<asp:Button ID="btnDelete" runat="server" Text="Delete"
OnClick="btnDelete_Click"
/><br /><br />
<asp:Label ID="lblResult10" runat="server" ForeColor="Green" /><br
/><br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="True"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
AutoGenerateSelectButton="True">
</asp:GridView>

</div>

</form>
</body>

</html>
[Link]:
using System; [Link];
using [Link]; [Link];
public partial class Program10 : [Link]
{
string connString =
[Link]["SchoolD
BConnectio
nString2"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadGrid();

}
private void LoadGrid()
{
using (SqlConnection conn = new
SqlConnection(connString))
{

string sql = "SELECT * FROM Students"; SqlDataAdapter da = new


SqlDataAdapter(sql,
conn); DataTable dt = new DataTable();
[Link](dt); [Link] = dt; [Link]();
}
}
protected void btnInsert_Click(object sender, EventArgs e)

using (SqlConnection conn = new


SqlConnection(connString))
{

[Link]();

string sql = "INSERT INTO Students (Name, Age) OUTPUT


[Link]
VALUES (@Name, @Age)";
using (SqlCommand cmd = new SqlCommand(sql, conn))

{
[Link]("@Name",[Link]);
[Link]("@Age", [Link]); int
newID =
(int)[Link]();
[Link] = [Link]();
[Link] = "Record inserted with ID: " + newID;
}

}
LoadGrid()
;

protected void btnUpdate_Click(object sender, EventArgs e)

if ([Link]([Link]))

{
[Link] = "Select a record to
update."; return;
}

using (SqlConnection conn = new SqlConnection(connString))

[Link]();

string sql = "UPDATE Students SET Name=@Name, Age=@Age


WHERE
StudentID=@ID";
using (SqlCommand cmd = new SqlCommand(sql, conn))

{
[Link]("@Name",[Link]);
[Link]("@Age", [Link]);
[Link]("@ID", [Link]);
int rows = [Link](); [Link] = rows + " row(s)
updated.";
}

LoadGrid();

}
protected void btnDelete_Click(object sender, EventArgs e)

if ([Link]([Link]))

[Link] = "Select a record to delete."; return;


}

using (SqlConnection conn = new SqlConnection(connString))

[Link]();

string sql = "DELETE FROM Students WHERE StudentID=@ID"; using (SqlCommand cmd
= new SqlCommand(sql, conn))
{

[Link]("@ID",[Link]); int rows = [Link]();


[Link] = rows + " row(s) deleted.";
}
}
ClearForm();
LoadGrid();
}
protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
{
GridViewRow row = [Link]; [Link] = [Link][1].Text;
[Link] = [Link][2].Text; [Link] = [Link][3].Text;
}

private void ClearForm()

[Link] = ""; [Link] = ""; [Link] = "";


}

}
10. Database Application to Perform Insert, Update, Delete Operations

Output:
Insert, Update, Delete or View operations performed on Students table.
lblResult10 displays
number of affected rows.
10. Database Application to Perform Insert, Update, Delete Operations
11. Database Application Using Data Controls for CRUD with Paging and Sorting

[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]"
Inherits="Program11" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 11</title>
</head>
<body>
<form id="form2" runat="server">
<div>
<h3>Insert New Student</h3>
<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="txtName11" runat="server" /></td>
</tr>
<tr>
<td>Age:</td>
<td><asp:TextBox ID="txtAge11" runat="server"
/></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnInsert11" runat="server" Text="Insert"
OnClick="btnInsert11_Click" />
</td>
</tr>
</table>
<asp:Label ID="lblMessage11" runat="server" ForeColor="Green" />
<br /><br />
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False"
DataKeyNames="StudentID"DataSourceID="SqlDataSource1"
AllowPaging="True"
AllowSorting="True" PageSize="5">
<Columns>
<asp:BoundField DataField="StudentID" HeaderText="ID"
ReadOnly="True"
SortExpression="StudentID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Age" HeaderText="Age"
SortExpression="Age" />
<asp:CommandFieldShowEditButton="True" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:SchoolDBConnectionString2 %>"
SelectCommand="SELECT StudentID, Name, Age FROM Students"
UpdateCommand="UPDATE Students SET Name=@Name, Age=@Age
WHERE
StudentID=@StudentID"
DeleteCommand="DELETE FROM Students WHERE StudentID=@StudentID">
<UpdateParameters>
<asp:Parameter Name="Name"
Type="String" />
<asp:Parameter Name="Age"
Type="Int32" />
<asp:Parameter Name="StudentID"
Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="StudentID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>

[Link]:

using System;
[Link]; using [Link];
using [Link]; [Link];
[Link]; using [Link];
public partial class Program11 : [Link]
{
string connString =
[Link]["SchoolD
BConnectio
nString2"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)

}
protected void btnInsert11_Click(object sender,
EventArgs e)

{
if ([Link]() == "" || [Link]() == "")

[Link] = "Please enter Name and Age.";


[Link] =
[Link]; return;
}
using (SqlConnection conn = new SqlConnection(connString))

[Link]();
string sql = "INSERT INTO Students (Name, Age) VALUES
(@Name,
@Age)";

using (SqlCommand cmd = new SqlCommand(sql, conn))


{

[Link]("@Name",[Link]());
[Link]("@Age", [Link]()); int rows =
[Link]();
[Link] = $"{rows} row(s) inserted."; [Link] =
[Link];
}

}
[Link] = ""; [Link] = "";

[Link](); // refresh grid

}
11. Database Application Using Data Controls for CRUD with Paging and Sorting

Output:

GridView displays Students data with Edit, Delete buttons, and supports paging(more than 5
records display in next page) and sorting (ID, Name, Age).
12. Implement XML Classes

[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]"
Inherits="Program12" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Program 12</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnRead" runat="server" Text="Read XML" OnClick="btnRead_Click"
/><br /><br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="True"></asp:GridView><br
/><br />
ID: <asp:TextBox ID="txtID12"
runat="server"></asp:TextBox><br
/><br />
Name: <asp:TextBox ID="txtName12"
runat="server"></asp:TextBox><br /><br /> Age: <asp:TextBox
ID="txtAge12"
runat="server"></asp:TextBox><br /><br />
<asp:Button ID="btnWrite" runat="server" Text="Write XML"
OnClick="btnWrite_Click"
/><br /><br />
<asp:Label ID="lblStatus12" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

[Link]:
using System; [Link]; using
[Link];

public partial class Program12 : [Link]

protected void btnRead_Click(object sender, EventArgs e)

{
XmlDocument xmlDoc = new XmlDocument();
[Link]([Link]("~/App_Data/[Link]")); XmlNodeList
nodes =
[Link]("/Students/Student");
DataTable dt = new DataTable(); [Link]("StudentID");
[Link]("Name");

[Link]("Age");
foreach (XmlNode node in
nodes)
{
DataRow dr = [Link]();

dr["StudentID"] = node["StudentID"].InnerText; dr["Name"] =


node["Name"].InnerText;
dr["Age"] = node["Age"].InnerText; [Link](dr);
}
[Link] = dt; [Link]();
}
protected void btnWrite_Click(object sender, EventArgs e)

string filePath =
[Link]("~/App_Data/[Link]");
XmlDocument xmlDoc = new XmlDocument();

// If file exists, load and append


if([Link](filePath))
{

[Link](filePath);

XmlNode root = [Link];


XmlElement student =
[Link]("Student");

XmlElement id = [Link]("StudentID"); [Link] =


[Link];
[Link](id);

XmlElement name = [Link]("Name"); [Link] =


[Link];
[Link](name);

XmlElement age = [Link]("Age"); [Link] =


[Link];
[Link](age);

[Link](student);
}

else

// If file doesn't exist, create new structure

XmlDeclaration xmlDecl = [Link]("1.0",


"UTF-8", null);
[Link](xmlDecl);

XmlElement root = [Link]("Students"); [Link](root);

XmlElement student = [Link]("Student");

XmlElement id = [Link]("StudentID"); [Link] = [Link];

[Link](id);

XmlElement name = [Link]("Name"); [Link] = [Link];


[Link](name);

XmlElement age = [Link]("Age"); [Link] = [Link];


[Link](age);

[Link](student);
}

[Link](filePath);

[Link] = "Student added to XML file.";

}
12. Implement XML Classes

Output:
Enter ID, Name, Age and click Write XML to create [Link] and
display success
message. Click Read XML to populate GridView from [Link].
13. Implement Authentication–Authorization
[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]"
Inherits="Program13" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Login Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtUser" runat="server" Placeholder="Username"></asp:TextBox><br
/><br />
<asp:TextBox ID="txtPass" runat="server" TextMode="Password"
Placeholder="Password"></asp:TextBox><br /><br />
<asp:Button ID="btnLogin" runat="server" Text="Login"
OnClick="btnLogin_Click" /><br
/><br />
<asp:Label ID="lblError" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

[Link]:
using System;
using [Link];
public partial class Login : [Link]
{
protected void btnLogin_Click(object sender, EventArgs e)
{
if ([Link] == "admin" && [Link] == "admin")
{
[Link]([Link]
, false);
[Link]("[Link]");
}
else
{
[Link] = "Invalid
credentials.";
}
}
}
[Link]:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="[Link]"


Inherits="Welcome"
%>
<!DOCTYPE html>
<html xmlns="[Link]
<head
runat="server">
<title>Welcome</tit
le>
</head>
<body>
<form id="form1"
runat="server">
<div>
<h1> Welcome Admin
</h1>
</div>
</form>
</body>
</html>
13. Implement Authentication–Authorization

Output:

[Link] authenticates user "admin"/"admin". On success, redirects to [Link]


showing "Welcome, admin".
14. Ticket Reservation Using [Link] Controls

[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]"
Inherits="Program14" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Ticket Reservation</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Source: <asp:DropDownList ID="ddlSource" runat="server">
<asp:ListItem>City A</asp:ListItem>
<asp:ListItem>City B</asp:ListItem>
</asp:DropDownList><br /><br />
Destination: <asp:DropDownList ID="ddlDestination" runat="server">
<asp:ListItem>City X</asp:ListItem>
<asp:ListItem>City Y</asp:ListItem>
</asp:DropDownList><br /><br />
<asp:Calendar ID="Calendar1"
runat="server"></asp:Calendar><br
/><br />
<asp:Button ID="btnReserve" runat="server" Text="Reserve
Ticket" OnClick="btnReserve_Click" /><br /><br />
<asp:Label ID="lblTicket" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
[Link]:
using System;
public partial class Program14 : [Link]
{
protected void btnReserve_Click(object sender,
EventArgs e)
{
[Link] = "Ticket Reserved: From " + [Link] + " to " +
[Link] + ";
Date: " +
[Link]
ng();
}
}
14. Ticket Reservation Using [Link] Controls

Output:
Displays reservation details: source, destination, and selected date after clicking Reserve
Ticket.
15. Online Examination Using [Link] Controls

[Link]:

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="[Link]"
Inherits="Program15" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Online Examination</title>
</head>

<body>
<form id="form1" runat="server">
<div>
<h4>1. What is the capital of India?<br /></h4>
<asp:RadioButtonList ID="rblQ1" runat="server">
<asp:ListItem>New Delhi</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Kerala</asp:ListItem>
</asp:RadioButtonList><br /><br />
<h4>2. Select programming languages:<br /></h4>
<asp:CheckBoxList ID="cblQ2" runat="server">
<asp:ListItem Text="C" Value="C#"></asp:ListItem>
<asp:ListItem Text="HTML" Value="HTML"></asp:ListItem>
<asp:ListItem Text="Java" Value="Java"></asp:ListItem>
</asp:CheckBoxList><br /><br />
<asp:Button ID="btnSubmitExam" runat="server"
Text="Submit Exam"
OnClick="btnSubmitExam_Click" /><br /><br />
<asp:Label ID="lblScore" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
[Link]:

using System;

public partial class Program15 : [Link]


{

protected void btnSubmitExam_Click(object sender, EventArgs e)

int score = 0;

if ([Link] == "New Delhi") score += 5;

foreach ([Link] li in [Link])

if ([Link] && ([Link] == "C" || [Link] == "Java")) score+= 5;

[Link] = "Your Score: " + score;

}
15. Online Examination Using [Link] Controls

Output:
Displays score: 5 points for each correct answer (Q1 and Q2).

You might also like