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

ASP.NET Practicals-3

The document outlines a series of practical programming tasks in C# and ASP.NET, including creating applications for basic arithmetic operations, Floyd's triangle, Fibonacci series, prime number testing, and demonstrating concepts like boxing/unboxing, delegates, and interfaces. It also includes tasks for web applications involving server controls, validation, cookies, and data binding with GridView and DetailsView. Each task is accompanied by sample code and expected outputs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

ASP.NET Practicals-3

The document outlines a series of practical programming tasks in C# and ASP.NET, including creating applications for basic arithmetic operations, Floyd's triangle, Fibonacci series, prime number testing, and demonstrating concepts like boxing/unboxing, delegates, and interfaces. It also includes tasks for web applications involving server controls, validation, cookies, and data binding with GridView and DetailsView. Each task is accompanied by sample code and expected outputs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 103

Index

Sr.
Practical Question Signature
No.
1. Write the program for the following:

a. Create an application to print on screen the output of adding, subtracting,


multiplying and dividing two numbers entered by the user in C#.
b. Create an application to print Floyd’s triangle till n rows in C#.

c. Create an application to demonstrate following operations i. Generate Fibonacci


series. ii. Test for prime numbers.
2. Write the program for the following:

a. Create a simple application to demonstrate the concepts boxing and unboxing.

b. Create a simple application to perform addition and subtraction using delegate.

c. Create a simple application to demonstrate use of the concepts of interfaces.

3. Write the program for the following:

a. Create a simple web page with various server controls to demonstrate setting and
use of their properties. (Example : AutoPostBack)
b. Create a simple application to demonstrate your vacation using calendar control.

c. Demonstrate the use of Treeview operations on the web form.

4. Write the program for the following:

a. Create a Registration form to demonstrate use of various Validation controls.

b. Create Web Form to demonstrate use of Adrotator Control.

c. Create Web Form to demonstrate use User Controls

5. Write the program for the following:

a. Create Web Form to demonstrate use of Website Navigation controls.


b. Create a web application to demonstrate use of Master Page and content page.

c. Create a web application to demonstrate various states of ASP.NET Pages.

6. Write the program for the following:

a. Create a web application to display Using Disconnected Data Access and


Databinding using GridView.
7. Write the program for the following:

a. Create a web application to demonstrate the use of different types of Cookies.

b. Create a web application to demonstrate Form Security and Windows Security


with proper
Authentication and Authorization properties.
8. Write the program for the following:

a. Create a web application for inserting and deleting records from a database.
(Using Execute-Non Query).
b. Create a web application for user defined exception handling.

9. Write the program for the following:

a. Create a web application to demonstrate use of GridView button column and


GridView events
along with paging and sorting.
b. Create a web application to demonstrate data binding using DetailsView and
FormView Control.
10. Write the program for the following:

a. Create a web application to demonstrate JS Bootstrap Button.

b. Create a web application to demonstrate use of various Ajax controls.

c. Create a web application to demonstrate Installation and use of NuGet package.


Practical 1: Write the program for the
following:
Practical 1(A): Create an application to print on screen
the output of adding, subtracting, multiplying and
dividing two numbers entered by the user in C#.
INPUT:
using System;
namespace numbers
{
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Enter 2 numbers :");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Addition of the numbers is
: " + (a+b));
Console.WriteLine("Substraction of the numbers
is : " + (a-b));
Console.WriteLine("Multiplication of the
numbers is : " + (a * b));
Console.WriteLine("Division of the numbers is
: " + (a / b));
Console.ReadKey();
}
}
}
OUTPUT:
Practical 1(B): Create an application to print Floyd’s
triangle till n rows in C#.
INPUT:

using System;
class Program
{
static void Main()
{
Console.Write("Enter the number of rows: ");
int n = int.Parse(Console.ReadLine());
int number = 1;

for (int i = 1; i <= n; i++)


{
for (int j = 1; j <= i; j++)
{
Console.Write(number++ + " ");
}
Console.WriteLine();

}
Console.ReadKey();
}
}

OUTPUT:
Practical 1(C): Create an application to demonstrate
following operations i. Generate Fibonacci series. ii.
Test for prime numbers.
i.Generate Fibonacci series:
INPUT:
using System;
namespace Fibonacci
{
class Program
{
static void Main(string[] args)
{
int a = 0, b = 1, c, n;
Console.Write("Enter a number : ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("First "+ n +" Fibonacci numbers are :\n" +
a + "\t" + b);
for (int i = 2; i < n; i++)
{
c = a + b;
a = b;
b = c;
Console.Write("\t" + c);
}
Console.ReadKey();
}
}
}
OUTPUT:
ii. Test for prime numbers.
INPUT:

using System;
namespace Prime
{
class Program
{
static void Main(string[] args)
{
int num, i;
Console.Write("Enter a number :");
num = Convert.ToInt32(Console.ReadLine());
for (i = 2; i < num; i++)
{
if (num % i == 0)
{
break;
}
}
if (i == num)
Console.WriteLine(num + " is a Prime
Number");
else
Console.WriteLine(num + " is not a Prime
Number");
Console.ReadKey();
}
}
}
OUTPUT:
Practical 2: Write the program for the
following:
Practical 2(A): Create a simple application to
demonstrate the concepts boxing and unboxing.
INPUT:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int m;
Console.Write("Enter an integer value: ");
m = int.Parse(Console.ReadLine());

object om = m;
m = 20;
Console.WriteLine("Boxed value: " + om);
int j = (int)om;
Console.WriteLine("Unboxed value: " + j);
Console.ReadKey();

}
}
}
OUTPUT:
Practical 2(B): Create a simple application to perform
addition and subtraction using delegate.
INPUT:
using System;
namespace DelagationDemo
{
public delegate void demo(int a,int b);
class Program
{
public static void add(int a,int b)
{
Console.WriteLine("Addition = " + (a+b));
}
public static void sub(int a,int b)
{
Console.WriteLine("Subtraction = " + (a-b));
}
static void Main(string[] args)
{
demo mathOps = new demo(add);
mathOps += new demo(sub);
Console.WriteLine("Enter two numbers:");
int num1 = int.Parse(Console.ReadLine());
int num2 = int.Parse(Console.ReadLine());
mathOps(num1, num2);
Console.Read();
}
}
}
OUTPUT:
Practical 2(C): Create a simple application to
demonstrate use of the concepts of interfaces.
INPUT:
using System;
namespace Interface
{
public interface A
{
void display();
}
public interface B
{
void display1();
}
public class C : A, B
{
public void display()
{
Console.WriteLine("A class method called");
}
public void display1()
{
Console.WriteLine("B class method called");
}
public void display2()
{
Console.WriteLine("C class method called");
}
}
public class Program
{
public static void Main(string[] args)
{
C obj = new C();
obj.display();
obj.display1();
obj.display2();
Console.ReadKey();
}
}
}
OUTPUT:
Practical 3: Write the program for the
following:
Practical 3(A): Create a simple web page with various
server controls to demonstrate setting and use of
their properties. (Example : AutoPostBack)
INPUT:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0


Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Resume</h1>
Name :<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<br />
<br />
Age :<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
<br />
<br />
Email :<asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox>
<br />
<br />
Phone no.
<asp:TextBox ID="TextBox4"
runat="server"></asp:TextBox>
<br />
<br />
Res.Address :<asp:TextBox ID="TextBox5"
runat="server"></asp:TextBox>
<br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server"
AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged"
Text="both" />
<br />
<br />

Native Address:
<asp:TextBox ID="TextBox6"
runat="server"></asp:TextBox>
<br />
<br />
Password :<asp:TextBox ID="TextBox7"
runat="server"></asp:TextBox>
<br />
<br />
Courses<asp:DropDownList ID="DropDownList1"
runat="server"

onselectedindexchanged="DropDownList1_SelectedIndexChanged
"
AutoPostBack="True">
<asp:ListItem>Select course</asp:ListItem>
<asp:ListItem>BSC-It</asp:ListItem>
<asp:ListItem>BCA</asp:ListItem>
<asp:ListItem>BMS</asp:ListItem>
<asp:ListItem>BAF</asp:ListItem>
<asp:ListItem>BBI</asp:ListItem>
<asp:ListItem>B.com</asp:ListItem>
<asp:ListItem>MSC-IT</asp:ListItem>
<asp:ListItem>MCA</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
<br />
<asp:Button ID="Submit" runat="server" Text="Submit"
onclick="Submit_Click" />
<br />
<asp:Label ID="Label2" runat="server"
Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void
DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
Label1.Text = "Selected Course is :" +
DropDownList1.SelectedItem;
}
protected void Submit_Click(object sender, EventArgs
e)
{
Label2.Text = "you form has been submitted";
}
protected void CheckBox1_CheckedChanged(object
sender, EventArgs e)
{
TextBox6.Text = TextBox5.Text;
}

}
OUTPUT:
Practical 3(B): Create a simple application to
demonstrate your vacation using calendar control.
INPUT:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0


Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Calendar ID="Calendar1" runat="server"


BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px"

OnSelectionChanged="Calendar1_SelectionChanged"
NextPrevFormat="ShortMonth"
OnDayRender="Calendar1_DayRender"
Font-Names="Verdana" Font-Size="8pt"
ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="252px"
style="text-align: left"
DayNameFormat="Shortest" >
<DayHeaderStyle BackColor="#FFCC66" Font-
Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt"
ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-
Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-
Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66"
ForeColor="White" />
</asp:Calendar><br/>
<asp:Label ID="Label1"
runat="server"></asp:Label><br />
<asp:Label ID="Label2"
runat="server"></asp:Label><br />
<asp:Label ID="Label3"
runat="server"></asp:Label><br />
<asp:Label ID="Label4"
runat="server"></asp:Label> <br />
<asp:Label ID="Label5"
runat="server"></asp:Label> <br /> <br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Submit" />
<asp:Button ID="Button2" runat="server"
OnClick="Button2_Click" Text="Reset" /><br />
</div></form></body></html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs
e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}

protected void Calendar1_SelectionChanged(object


sender, EventArgs e)
{
Label1.Text = "Your Selected Date:" +
Calendar1.SelectedDate.Date.ToString();
}
protected void Calendar1_DayRender(object
sender,System.Web.UI.WebControls.DayRenderEventArgs e)
{
if (e.Day.Date.Day == 7 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2024, 9,
7);

Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate
,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati!";
e.Cell.Controls.Add(lbl1);
Image g1 = new Image();
g1.ImageUrl = "image.jpeg";
g1.Height = 20;
g1.Width = 20;
e.Cell.Controls.Add(g1);
}
}
protected void Button1_Click(object sender, EventArgs
e)
{
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month ;
Label2.Text = "Todays Day
"+Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "Ganpati Vacation Start: 7-9-2024";
TimeSpan d = new DateTime(2024, 9, 7) - DateTime.Now;
Label4.Text = "Days Remaining For Ganpati Vacation:" +
d.Days.ToString();
TimeSpan d1 = new DateTime(2024, 12, 31) - DateTime.Now;
Label5.Text = "Days Remaining for New Year:" +
d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "7-9-
2024")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "17-9-
2024")
Label3.Text = "<b>Ganpati Festival End</b>";
}
}
OUTPUT:
Practical 3(C): Demonstrate the use of Treeview
operations on the web form.
INPUT:
Home.aspx(Treeview operations)
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="home.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<p>
<img alt="" class="style1" src="th%20(1).jpeg"
height="300px" width="500px" /></p>
<p>
&nbsp;SHAILENDRA DEGREE COLLEGE</p>
<asp:TreeView ID="TreeView1" runat="server"
ImageSet="Arrows">
<HoverNodeStyle Font-Underline="True"
ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode NavigateUrl="~/home.aspx"
Text="Home" Value="Home"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/about.aspx"
Text="About Us" Value="About Us">
</asp:TreeNode>
<asp:TreeNode NavigateUrl="~/contact.aspx"
Text="Contact Us" Value="Contact Us">
</asp:TreeNode>
<asp:TreeNode NavigateUrl="~/courses.aspx"
Text="Courses" Value="Courses">
<asp:TreeNode
NavigateUrl="~/bscit.aspx" Text="bscit" Value="bscit">
</asp:TreeNode>
<asp:TreeNode NavigateUrl="~/bca.aspx"
Text="BCA" Value="BCA">
</asp:TreeNode>
<asp:TreeNode NavigateUrl="~/bms.aspx"
Text="BMS" Value="BMS">
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Tahoma" Font-
Size="10pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px"
VerticalPadding="0px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle Font-Underline="True"
ForeColor="#5555DD"
HorizontalPadding="0px"
VerticalPadding="0px" />
</asp:TreeView>
</form>
</body>
</html>
About.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="about.aspx.cs" Inherits="about" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Shailendra Education Society’s Arts, Commerce and
Science College</h2>
Shailendra Education Society’s Arts, Commerce and
Science College was established in 1994 with the launch of
Commerce faculty.
The Arts faculty was started in the year 1996. The
college began with the primary objective of providing
education to the lower socio-economic strata of
the society who are very often the first generation
learners.
To increase the employability of the students the
college launched self-finance courses from 2004 onwards.
Under the self-finance courses BBI, BMS and B.Sc. (IT)
courses are offered. The college has been sanctioned
Research Centre in the Subject
of Business Economics under the faculty of Commerce
The College has undergone NAAC reaccreditation process
in November 2011 and has been awarded B grade with CGPA of
2.92.
</div>
</form>
</body>
</html>
Contact.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="contact.aspx.cs" Inherits="contact" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Contact Us</h1>
Name :<input id="Text1" type="text"/><br />
Age :<input id="Text2" type="number" /><br />
Email :<input id="Text3" type="email" /><br />
Phone no. <input id="Text4" type="text" /><br />
Address :<input id="Text5" type="text" /><br />
Password :<input id="Text6" type="password" /><br />
<asp:Button ID="Button1" runat="server"
Text="submit" /><br />
</div>
</form>
</body>
</html>

Courses.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="courses.aspx.cs" Inherits="courses" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
courses are:<br />
BSCIT <br />

BCA<br />

BMS <br />


</div>
</form>
</body>
</html>
Bsc-IT.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="bscit.aspx.cs" Inherits="courses" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BSC-IT</h1>
<p> The BSc IT course is a programme of study in
software development, software testing,
software engineering, web design, databases,
programming, computer networking and computer systems.
BSc IT course graduates are qualified to perform
tasks related to the processing, storing, and
communication of information between computers,
mobile phones, and other electronic devices. It is
essential for candidates who wish to build a career in the
field of programming, network or database management.
Those who are passionate about learning how to hande
computer systems can choose this course. Candidates
interested in pursuing a BSc IT
and Software can check all the relevant details
below</p>
</div>
</form>
</body>
</html>

Bca.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="bca.aspx.cs" Inherits="bms" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BCA</h1>
<p>
A Bachelor of Computer Applications (BCA) is a three-
year undergraduate degree program that prepares students
for careers in IT.
The course covers a range of topics, including:
Programming languages: Students learn to program in
languages like C, C++, Java, and Python.
Database management: Students learn about database
design, implementation, and management, including SQL,
database normalization, and data modeling.
</p>
</div>
</form>
</body>
</html>
Bms.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="bms.aspx.cs" Inherits="bms" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BMS</h1>
<p>
MS (Bachelor of Management Studies) is a 3-year
undergraduate course designed to study analytical aspects
of Business Management
and get in-depth knowledge in several managerial or
business-related subjects such as human resource
management, economics, marketing, and business analytics.
Bachelor of Management Studies is offered in both full-
time and part-time mode across Top BMS Colleges in India.
Candidates who wish to apply for BMS Courses must fulfill
the minimum eligibility criteria</p>
</div>
</form>
</body>
</html>
OUTPUT:
Practical 4: Write the program for the
following:
Practical 4(A): Create a Registration form to
demonstrate use of various Validation controls.
INPUT:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server"><div>
Name:<asp:TextBox ID="t1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="t1" ErrorMessage="Enter Name"> *
</asp:RequiredFieldValidator> <br />
Age: <asp:TextBox ID="t2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="t2" ErrorMessage="Enter
Age">*</asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="t2"
ErrorMessage="Age Out of Range" MaximumValue="99"
MinimumValue="15">*</asp:RangeValidator><br />
Email: <asp:TextBox ID="t3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server" ControlToValidate="t3" ErrorMessage="Enter
correct Email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-
.]\w+)*\.\w+([-
.]\w+)*">*</asp:RegularExpressionValidator><br />
Password : <asp:TextBox ID="t4" runat="server"
TextMode="Password"
CausesValidation="True"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="t4" ErrorMessage="Password too Short"
OnServerValidate="CustomValidator1_ServerValidate"
ValidateEmptyText="True">*</asp:CustomValidator><br />
Confirm Password : <asp:TextBox ID="t5" runat="server"
TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1"
runat="server"
ControlToCompare="t4" ControlToValidate="t5"
ErrorMessage="Password Didn't
Match">*</asp:CompareValidator><br /><br />
<asp:Button ID="Button1" runat="server" Text="Submit"
/><br />
<asp:ValidationSummary ID="ValidationSummary1"
runat="server" /><br /><br />
<asp:Label ID="l1" runat="server"></asp:Label>
</div></form></body></html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object
source,
ServerValidateEventArgs args)
{
if ((args.Value).Length < 8)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
l1.Text = "Hello " + t1.Text;
}
}
}
OUTPUT:
Practical 4(B): Create Web Form to demonstrate use of
Adrotator Control.
INPUT:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<asp:AdRotator ID="AdRotator1" runat="server"
AdvertisementFile="~/XMLFile.xml"/>
</center>
</div>
</form>
</body>
</html>

XMLFile.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>rose1.jpg</ImageUrl>
<NavigateUrl>http://www.1800flowers.com</NavigateUrl>
<AlternateText>
Order flowers, roses, gifts and more
</AlternateText>
<Impressions>20</Impressions>
<Keyword>flowers</Keyword>
</Ad>
<Ad>
<ImageUrl>rose2.jpg</ImageUrl>

<NavigateUrl>http://www.babybouquets.com.au</NavigateUrl>
<AlternateText>Order roses and flowers</AlternateText>
<Impressions>20</Impressions>
<Keyword>gifts</Keyword>
</Ad>
<Ad>
<ImageUrl>rose3.jpg</ImageUrl>

<NavigateUrl>http://www.flowers2moscow.com</NavigateUrl>
<AlternateText>Send flowers to Russia</AlternateText>
<Impressions>20</Impressions>
<Keyword>russia</Keyword>
</Ad>
<Ad>
<ImageUrl>rose4.jpg</ImageUrl>
<NavigateUrl>http://www.edibleblooms.com</NavigateUrl>
<AlternateText>Edible Blooms</AlternateText>
<Impressions>20</Impressions>
<Keyword>gifts</Keyword>
</Ad>
</Advertisements>
OUTPUT:

Onclick :
More Ads :
Practical 4(C): Create Web Form to demonstrate use
User Controls
INPUT:
WebUserControl.ascx :
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="WebUserControl.ascx.cs"
Inherits="WebUserControl" %>
Number<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<p>
&nbsp;</p>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click"
Text="Calculate" />
<p>
&nbsp;</p>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>

WebUserControl.ascx.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebUserControl :


System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs


e)
{

int number;

if (int. TryParse(TextBox1.Text, out number) &&


number >= 0)

int fact = 1;
for (int i = 1; i <= number; i++)
{
fact *= i;
}

Label1.Text = "Factorial of "+ number + " is: "


+ fact;
}
else
{

Label1.Text = "Please enter a valid non-negative


integer.";
}
}
}

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="uc"
TagName="mycontrol" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:mycontrol ID="control1" runat="server"
EnableTheming="false" EnableViewState="false" />
</div>
</form>
</body>
</html>

OUTPUT:
Practical 5: Write the program for the
following:
Practical 5(A): Create Web Form to demonstrate use
of Website Navigation controls.
INPUT:
Web.sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-
1.0" >
<siteMapNode url="home.aspx" title="home"
description="">
<siteMapNode url="about.aspx" title="about"
description="" />
<siteMapNode url="contact.aspx" title="contact"
description="" />
<siteMapNode url="courses.aspx" title="courses"
description="" >
<siteMapNode url="bca.aspx" title="BA"
description="" />
<siteMapNode url="bms.aspx" title="BMS"
description="" />
<siteMapNode url="bscit.aspx" title="BSCIT"
description="" />
</siteMapNode>
</siteMapNode>
</siteMap>

home.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="home.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<p>
<img alt="" class="style1" src="th%20(1).jpeg"
height="300px" width="500px" /></p>
<p>
&nbsp;SHAILENDRA DEGREE COLLEGE</p>
<asp:Menu ID="Menu1" runat="server"
Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/about.aspx"
Text="about" Value="about"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/contact.aspx"
Text="conatct" Value="conatct"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/courses.aspx"
Text="courses" Value="courses">
<asp:MenuItem NavigateUrl="~/bca.aspx"
Text="bca" Value="bca"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/bms.aspx"
Text="bms" Value="bms"></asp:MenuItem>
<asp:MenuItem
NavigateUrl="~/bscit.aspx" Text="bscit"
Value="bscit"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</form>
</body>
</html>

about.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="about.aspx.cs" Inherits="about" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Shailendra Education Society’s Arts, Commerce and
Science College</h2>
Shailendra Education Society’s Arts, Commerce and
Science College was established in 1994 with the launch of
Commerce faculty.
The Arts faculty was started in the year 1996. The
college began with the primary objective of providing
education to the lower socio-economic strata of
the society who are very often the first generation
learners.
To increase the employability of the students the
college launched self-finance courses from 2004 onwards.
Under the self-finance courses BBI, BMS and B.Sc. (IT)
courses are offered. </div>
<asp:Menu ID="Menu1" runat="server"
Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</form>
</body>
</html>

contact.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="contact.aspx.cs" Inherits="contact" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Contact Us</h1>
Name :<input id="Text1" type="text"/><br />
Age :<input id="Text2" type="number" /><br />
Email :<input id="Text3" type="email" /><br />
Phone no. <input id="Text4" type="text" /><br />
Address :<input id="Text5" type="text" /><br />
Password :<input id="Text6" type="password" /><br />
<asp:Button ID="Button1" runat="server"
Text="submit" /><br />
<asp:Menu ID="Menu1" runat="server"
Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</div>
</form>
</body>
</html>

courses.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="courses.aspx.cs" Inherits="courses" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
courses are:<br />
BCA<br />

BMS<br />

BSCIT<br />
<asp:Menu ID="Menu1" runat="server"
Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</div>
</form>
</body>
</html>

Bca.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="bca.aspx.cs" Inherits="bms" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BCA</h1>
<p>
A Bachelor of Computer Applications (BCA) is a three-
year undergraduate degree program that prepares students
for careers in IT.
The course covers a range of topics, including:
Programming languages: Students learn to program in
languages like C, C++, Java, and Python.
Database management: Students learn about database
design, implementation, and management, including SQL,
database normalization, and data modeling.
<asp:Menu ID="Menu1" runat="server"
Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/courses.aspx"
Text="courses" Value="courses"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</p>
</div>
</form>
</body>
</html>

Bms.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="bms.aspx.cs" Inherits="bms" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BMS</h1>
<p>
MS (Bachelor of Management Studies) is a 3-year
undergraduate course designed to study analytical aspects
of Business Management
and get in-depth knowledge in several managerial or
business-related subjects such as human resource
management, economics, marketing, and business analytics.
Bachelor of Management Studies is offered in both full-
time and part-time mode across Top BMS Colleges in India.
Candidates who wish to apply for BMS Courses must fulfill
the minimum eligibility criteria</p>
<asp:Menu ID="Menu1" runat="server"
Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/courses.aspx"
Text="courses" Value="courses"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</div>
</form>
</body>
</html>

Bsc-IT.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="bscit.aspx.cs" Inherits="courses" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>BSC-IT</h1>
The BSc IT course is a programme of study in
software development, software testing,
software engineering, web design, databases,
programming, computer networking and computer systems.
BSc IT course graduates are qualified to perform
tasks related to the processing, storing, and
communication of information between computers,
mobile phones, and other electronic devices. It is
essential for candidates who wish to build a career in the
field of programming, network or database management.
Those who are passionate about learning how to hande
computer systems can choose this course. Candidates
interested in pursuing a BSc IT
and Software can check all the relevant details
below.
<h3>Who can pursue BSc IT?</h3>

<asp:Menu ID="Menu1" runat="server"


Orientation="Horizontal"
BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx"
Text="home" Value="home"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/courses.aspx"
Text="courses" Value="courses"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#7C6F57"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" />
</div>
</form>
</body>
</html>

OUTPUT:
Practical 5(B): Create a web application to
demonstrate use of Master Page and content page.
INPUT:
site.master:
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="site.master.cs" Inherits="site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.style1
{
width: 333px;
height: 228px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<p><img alt="" class="style1" src="th%20(1).jpeg"
/></p>

<h1> SHAILENDRA DEGREE COLLEGE&nbsp;</h1>


<p>
&nbsp;</p>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1"
runat="server">

</asp:ContentPlaceHolder>
</div>
</form>
<p>
&nbsp;</p>
</body>
</html>

Default.aspx:
<%@ Page Title="" Language="C#"
MasterPageFile="~/site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head"
Runat="Server">
</asp:Content>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
Welcome Home Page</p>
<p>
Name:<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</p>
<p>
Age:<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Submit"
/>
</p>
<p>
<asp:LinkButton ID="LinkButton1" runat="server"
PostBackUrl="~/Default2.aspx">Next Page</asp:LinkButton>
</p>
</asp:Content>

Default1.aspx:
<%@ Page Title="" Language="C#"
MasterPageFile="~/site.master" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head"
Runat="Server">
</asp:Content>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
Welcome Second Page</p>
<p>
<asp:LinkButton ID="LinkButton1" runat="server"
PostBackUrl="~/Default.aspx">Go to Home</asp:LinkButton>
</p>
</asp:Content>

OUTPUT:
Practical 5(C): Create a web application to
demonstrate various states of ASP.NET Pages.
INPUT:
View.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="VIEW.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0


Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<br />
<h1>VIEW STATE</h1>
<asp:Label ID="Label1" runat="server"
EnableViewState="False" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Plain" />
<br />
<br />
<asp:Button ID="Button2" runat="server"
Text="Postback" />
<br />
<br />
Res.Add<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server"
AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged"
Text="both" />
<br />
<br />
Native.Add<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>

</div>
</form>
</body>
</html>
View.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs
e)
{
Label1.Text = DateTime.Now.ToString();
}
protected void CheckBox1_CheckedChanged(object sender,
EventArgs e)
{
TextBox2.Text = TextBox1.Text;
}
}

OUTPUT:
Session.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Session.aspx.cs" Inherits="Session" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<h1>Session</h1>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server"


Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="post" />

</div>
</form>
</body>
</html>
Session.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Session : System.Web.UI.Page
{
int sessionCount;

protected void Page_Load(object sender, EventArgs e)


{
if (Session["count"] == null)
sessionCount=0;

else
sessionCount =Convert.ToInt32 (Session["count"]);
}

protected void Button1_Click(object sender, EventArgs e)


{

sessionCount++;

Label1.Text = "you have clicked the button" +


sessionCount;
}

protected void Page_PreRender(object sender, EventArgs e)


{
Session["count"]=sessionCount;
}
}
OUTPUT:

Application.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Application.aspx.cs" Inherits="Application" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Application</h1>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click"
Text="Click To Visit" />
</div>
</form>
</body>
</html>
Application.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Application : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs
e)
{

int count = 0;
if(Application["Visit"]!=null)
{
count = Convert.ToInt32(Application["Visit"].ToString());
}
count = count + 1;
Application["Visit"] = count;
Label1.Text = "Total Visit=" + count.ToString();
}
}
OUTPUT:
Practical 6: Write the program for the
following:
Practical 6(A): Create a web application to display
Using Disconnected Data Access and Databinding
using GridView.
INPUT:
Products table

Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET
application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="connstr" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Datab
ase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0"
/>
</system.web>
</configuration>
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server">


</asp:GridView>
<br />
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" Visible="False">
<Columns>
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" ReadOnly="True"
SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName"
SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice"
SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$
ConnectionStrings:connstr %>"
DeleteCommand="DELETE FROM [Products] WHERE
[ProductID] = @original_ProductID AND (([ProductName] =
@original_ProductName) OR ([ProductName] IS NULL AND
@original_ProductName IS NULL)) AND (([UnitPrice] =
@original_UnitPrice) OR ([UnitPrice] IS NULL AND
@original_UnitPrice IS NULL))"
InsertCommand="INSERT INTO [Products]
([ProductID], [ProductName], [UnitPrice]) VALUES
(@ProductID, @ProductName, @UnitPrice)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Products]"
UpdateCommand="UPDATE [Products] SET
[ProductName] = @ProductName, [UnitPrice] = @UnitPrice
WHERE [ProductID] = @original_ProductID AND
(([ProductName] = @original_ProductName) OR ([ProductName]
IS NULL AND @original_ProductName IS NULL)) AND
(([UnitPrice] = @original_UnitPrice) OR ([UnitPrice] IS
NULL AND @original_UnitPrice IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_ProductID"
Type="Int32" />
<asp:Parameter Name="original_ProductName"
Type="String" />
<asp:Parameter Name="original_UnitPrice"
Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductID"
Type="Int32" />
<asp:Parameter Name="ProductName"
Type="String" />
<asp:Parameter Name="UnitPrice"
Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName"
Type="String" />
<asp:Parameter Name="UnitPrice"
Type="String" />
<asp:Parameter Name="original_ProductID"
Type="Int32" />
<asp:Parameter Name="original_ProductName"
Type="String" />
<asp:Parameter Name="original_UnitPrice"
Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>

Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str =
ConfigurationManager.ConnectionStrings["connstr"].Connecti
onString;
SqlConnection con = new SqlConnection(str);
string selectSQL = "SELECT
ProductID,ProductName,UnitPrice FROM Products";
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
ViewState["Paging"] = ds;
GridView1.DataSource = ds;
GridView1.DataBind();

}
}
OUTPUT:
Practical 7: Write the program for the
following:
Practical 7(A): Create a web application to
demonstrate the use of different types of Cookies..
INPUT:
Cookie.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Cookie.aspx.cs" Inherits="Cookie" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click"
Text="Create Cookie" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
&nbsp;
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
&nbsp;<br />
<asp:Button ID="Button2" runat="server"
onclick="Button2_Click"
Text="Retrive Cookie" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>

Cookie.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Cookie : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs
e)
{
{
Response.Cookies["name"].Value =
TextBox1.Text;
Response.Cookies["name"].Expires =
DateTime.Now.AddMinutes(1);
Label1.Text = "Cookie Created";
TextBox1.Text = "";
}
}
protected void Button2_Click(object sender, EventArgs
e)
{
if (Request.Cookies["name"] == null)
{
TextBox2.Text = "No cookie found";
}
else
{
TextBox2.Text = Request.Cookies["name"].Value;
}
}
}
OUTPUT:
On Entering the value and Clicking on to the “Create Cookie” :

On Clicking on “Retrieve Cookie” :


Practical 7(B): Create a web application to
demonstrate Form Security and Windows Security
with proper Authentication and Authorization
properties.
INPUT:
How to set up authentication and authorization:
Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET
application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<compilation debug="false" targetFramework="4.0"
/>
</system.web>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="localhost" password=""
userName="" />
</smtp>
</mailSettings>
</system.net>
</configuration>

Createuser.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="createuser.aspx.cs" Inherits="createuser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1"
runat="server"
CancelDestinationPageUrl="~/createuser.aspx"
ContinueDestinationPageUrl="~/login.aspx">
<WizardSteps>
<asp:CreateUserWizardStep runat="server"
/>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>

Login.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="login.aspx.cs" Inherits="login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server"
CreateUserText="create new user"
CreateUserUrl="~/createuser.aspx"
DestinationPageUrl="~/pwdchange.aspx"
PasswordRecoveryText="forgot password"
PasswordRecoveryUrl="~/pwdrecovery.aspx">
</asp:Login>
</div>
</form>
</body>
</html>

pwdchange.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="pwdchange.aspx.cs" Inherits="pwdchange" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
Welcome<asp:LoginName ID="LoginName1" runat="server"
/>
&nbsp;<asp:LoginStatus ID="LoginStatus1" runat="server"
LogoutAction="RedirectToLoginPage"
LogoutPageUrl="~/login.aspx" />
<br />
<asp:ChangePassword ID="ChangePassword1"
runat="server"
CancelDestinationPageUrl="~/pwdchange.aspx"
ContinueDestinationPageUrl="~/login.aspx">
</asp:ChangePassword>
</form>
</body>
</html>

pwdrecovery.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="pwdrecovery.aspx.cs" Inherits="pwdrecovery" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:PasswordRecovery ID="PasswordRecovery1"
runat="server"
onsendingmail="PasswordRecovery1_SendingMail">
</asp:PasswordRecovery>
<br />
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
pwdrecovery.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pwdrecovery : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void PasswordRecovery1_SendingMail(object
sender, MailMessageEventArgs e)
{
Label1.Text = e.Message.Body.ToString();
e.Cancel = true;
}
}

OUTPUT:
Practical 8: Write the program for the
following:
Practical 8(A): Create a web application for inserting
and deleting records from a database. (Using Execute
Non Query).
INPUT:
Emp Table:

Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET
application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="conn"
connectionString="Data&#xD;&#xA;Source=.\SQLEXPRESS;Attach
DbFilename='C:\Users\lalit\Documents\Visual
Studio&#xD;&#xA;2010\WebSites\WebSite2\App_Data\Database.m
df';Integrated Security=True;User&#xD;&#xA;Instance=True"
/>
<add name="con" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Datab
ase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>&nbsp;<form id="form1" runat="server">
<div>
id.&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
sname&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
per:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
&nbsp;<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Insert" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server"
onclick="Button2_Click" Text="Delete" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
</div>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string str =
ConfigurationManager.ConnectionStrings["con"].ConnectionSt
ring;
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("insert into emp
values(" + TextBox1.Text + ",'"
+ TextBox2.Text + "'," + TextBox3.Text + ")", con);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Inserted Successfully";
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
string str =
ConfigurationManager.ConnectionStrings["con"].ConnectionSt
ring;
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("delete from emp where
sname='" + TextBox2.Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Deleted Successfully";
con.Close();
}
}
OUTPUT:
Insertion
Deletion:
Practical 8(B): Create a web application for user
defined exception handling.
INPUT:
using System;

class MyClient
{
public static void Main()
{
int x = 0;
int div = 0;

Console.WriteLine("Enter a number to divide 100


by:");
string input = Console.ReadLine();

if (!int.TryParse(input, out x))


{
Console.WriteLine("Invalid input! Please enter
a valid integer.");
return;
}

try
{
div = 100 / x;
Console.WriteLine("The division was
successful!");
}
catch (DivideByZeroException)
{
Console.WriteLine("Exception occurred: Cannot
divide by zero.");
}
finally
{
Console.WriteLine("Finally Block");
}

if (x != 0)
{
Console.WriteLine("Result is {0}", div);
}
else
{
Console.WriteLine("Result could not be
calculated due to division by zero.");
}

Console.ReadKey();
}
}
OUTPUT:
Practical 9: Write the program for the
following:
Practical 9(A): Create a web application to
demonstrate use of GridView button column and
GridView events along with paging and sorting.
INPUT:
Products table:

Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET
application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="connstr" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Datab
ase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0"
/>
</system.web>
</configuration>

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server"


AllowPaging="true" PageSize="2"

onpageindexchanging="GridView1_PageIndexChanging"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:CommandField ButtonType="Button"
ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
<br />
</div>
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" Visible="False">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" ReadOnly="True"
SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName"
SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice"
SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:connstr
%>"
DeleteCommand="DELETE FROM [Products] WHERE
[ProductID] = @original_ProductID AND (([ProductName] =
@original_ProductName) OR ([ProductName] IS NULL AND
@original_ProductName IS NULL)) AND (([UnitPrice] =
@original_UnitPrice) OR ([UnitPrice] IS NULL AND
@original_UnitPrice IS NULL))"
InsertCommand="INSERT INTO [Products]
([ProductID], [ProductName], [UnitPrice]) VALUES
(@ProductID, @ProductName, @UnitPrice)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName]
= @ProductName, [UnitPrice] = @UnitPrice WHERE [ProductID]
= @original_ProductID AND (([ProductName] =
@original_ProductName) OR ([ProductName] IS NULL AND
@original_ProductName IS NULL)) AND (([UnitPrice] =
@original_UnitPrice) OR ([UnitPrice] IS NULL AND
@original_UnitPrice IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_ProductID"
Type="Int32" />
<asp:Parameter Name="original_ProductName"
Type="String" />
<asp:Parameter Name="original_UnitPrice"
Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductID" Type="Int32"
/>
<asp:Parameter Name="ProductName"
Type="String" />
<asp:Parameter Name="UnitPrice" Type="String"
/>
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName"
Type="String" />
<asp:Parameter Name="UnitPrice" Type="String"
/>
<asp:Parameter Name="original_ProductID"
Type="Int32" />
<asp:Parameter Name="original_ProductName"
Type="String" />
<asp:Parameter Name="original_UnitPrice"
Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{

this.BindGrid();
}
}
private void BindGrid()
{
string str =
ConfigurationManager.ConnectionStrings["connstr"].Connecti
onString;
SqlConnection con = new SqlConnection(str);
string selectSQL = "SELECT
ProductID,ProductName,UnitPrice FROM Products";
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
ViewState["Paging"] = ds;
GridView1.DataSource = ds;
GridView1.DataBind();

}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int rowIndex =
Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[rowIndex];
string ProductID = row.Cells[1].Text;
string ProductName = row.Cells[2].Text;
string UnitPrice = row.Cells[3].Text;
Label1.Text = "ProductID: " + ProductID +
"\nName: " + ProductName + "\nPrice: " + UnitPrice;

}
protected void GridView1_PageIndexChanging(object
sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = ViewState["Paging"];
GridView1.DataBind();
}
}

OUTPUT:
Practical 9(B): Create a web application to
demonstrate data binding using DetailsView and
FormView Control..
INPUT:
Details table:

Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET
application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>

<connectionStrings>
<add name="connstr" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Datab
ase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0"
/>
</system.web>

</configuration>

Details.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="details.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0


Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:DetailsView ID="DetailsView1" runat="server"


Height="50px" AllowPaging="true"

onpageindexchanging="DetailsView1_PageIndexChanging"
PageSize="2" Width="125px">
</asp:DetailsView>
<br />

</div>
<asp:DetailsView ID="DetailsView2" runat="server"
AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px"
Width="125px" Visible="False">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id"
SortExpression="Id" />
<asp:BoundField DataField="Name"
HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Stream"
HeaderText="Stream"
SortExpression="Stream" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:connstr
%>"
SelectCommand="SELECT * FROM
[details]"></asp:SqlDataSource>
<br />
<br />
<br />
</form>
</body>
</html>

Details.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{

BindDetailView();

}
private void BindDetailView()
{
string str =
ConfigurationManager.ConnectionStrings["connstr"].Connecti
onString;
SqlConnection con = new SqlConnection(str);
string selectSQL = "SELECT ID, Name,Stream FROM
Details";
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
ViewState["Paging"] = ds;
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
}
protected void DetailsView1_PageIndexChanging(object
sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
this.BindDetailView();
}

OUTPUT:

form.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="form.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:FormView ID="FormView1" runat="server"

onpageindexchanging="FormView1_PageIndexChanging" >
</asp:FormView>
<br />
<asp:FormView ID="FormView2" runat="server"
DataSourceID="SqlDataSource1"
AllowPaging="True">
<EditItemTemplate>
Id:
<asp:TextBox ID="IdTextBox" runat="server"
Text='<%# Bind("Id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox"
runat="server" Text='<%# Bind("Name") %>' />
<br />
Stream:
<asp:TextBox ID="StreamTextBox"
runat="server" Text='<%# Bind("Stream") %>' />
<br />
<asp:LinkButton ID="UpdateButton"
runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton
ID="UpdateCancelButton" runat="server"
CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Id:
<asp:TextBox ID="IdTextBox" runat="server"
Text='<%# Bind("Id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox"
runat="server" Text='<%# Bind("Name") %>' />
<br />
Stream:
<asp:TextBox ID="StreamTextBox"
runat="server" Text='<%# Bind("Stream") %>' />
<br />
<asp:LinkButton ID="InsertButton"
runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton
ID="InsertCancelButton" runat="server"
CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Id:
<asp:Label ID="IdLabel" runat="server"
Text='<%# Bind("Id") %>' />
<br />
Name:
<asp:Label ID="NameLabel" runat="server"
Text='<%# Bind("Name") %>' />
<br />
Stream:
<asp:Label ID="StreamLabel" runat="server"
Text='<%# Bind("Stream") %>' />
<br />

</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings:connstr %>"
SelectCommand="SELECT * FROM
[details]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

form.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class Default2 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindFormView();
}

}
private void BindFormView()
{
string str =
ConfigurationManager.ConnectionStrings["connstr"].Connecti
onString;
SqlConnection con = new SqlConnection(str);
string selectSQL = "SELECT ID, Name,Stream FROM
Details";
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
ViewState["Paging"] = ds;
FormView1.DataSource = ds;
FormView1.DataBind();
}

protected void FormView1_PageIndexChanging(object


sender, FormViewPageEventArgs e)
{
FormView1.PageIndex = e.NewPageIndex;
this.BindFormView();
}
}

OUTPUT:
Practical 10: Write the program for the
following:

Practical 10(A): Create a web application to


demonstrate JS Bootstrap Button.
INPUT:
Typography.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Typography.aspx.cs"
Inherits="WebApplication2.Typography" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
<title></title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,
initial-scale=1" />
<link href="Content/bootstrap.min.css"
rel="stylesheet" />
<script src="Scripts/bootstrap.min.js"></script>
<script
src="Scripts/bootstrap.bundle.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p class="h1">This is Heading 1</p>
<p class="h2" >This is Heading 2</p>
<p class="h3">This is Heading 3</p>
<p class="h4">This is Heading 4</p>
<p class="h5">This is Heading 5</p>
<h3 class="display-3">this is display
property</h3>
<h3 class="display-4">this is display
property</h3>
<p class="text-muted">This is a muted
text</p>
<p class="text-lowercase">THIS IS LOWER
CASE</p>
<p class="text-uppercase">this is upper
case</p>
<mark>THIS IS MARK TAG</mark>
<p> <abbr title="world health
organization">WHO</abbr>was founded in 1948</p>
<p class="bg-primary">this text is
important</p>
<p class="bg-danger">this text represent is
danger</p>
<blockquote>this is blockquote
tag</blockquote>
<blockquote class="blockquote-footer">--
author name</blockquote>
</div>
</form>
</body>
</html>
OUTPUT:
Practical 10(B): Create a web application to
demonstrate use of various Ajax controls.
INPUT:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:scriptmanager ID="ScriptManager1"
runat="server"></asp:scriptmanager><br />
<asp:updatepanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Emp ID:
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<br />
Emp Name:<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server"
Text="Button" OnClick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="msg
send successfully" Visible="False"></asp:Label>
<br />
</ContentTemplate>
</asp:updatepanel>
<asp:UpdateProgress ID="UpdateProgress1"
runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img src="image.jpeg" />
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
</body>
</html>

Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs
e)
{

System.Threading.Thread.Sleep(3000);
Label1.Visible = true;
}
}
OUTPUT:
Practical 10(C): Create a web application to
demonstrate Installation and use of NuGet Package.
INPUT:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication7.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="nuget Demo" />
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Font-
Bold="False" Text="Label"></asp:Label>
<br />
</div>

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

Default.aspx.cs:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs
e)
{

}
protected void Button1_Click(object sender,
EventArgs e)
{
Account account = new Account
{
Name = "saurav sing",
Email = "[email protected]",
DOB = new DateTime(1982, 12, 13, 0, 0, 0,
DateTimeKind.Local),
};
string json =
JsonConvert.SerializeObject(account,
Newtonsoft.Json.Formatting.Indented);
Label1.Text = json;
}
}
public class Account // Ensure this class is defined
{
public string Name { get; set; }
public string Email { get; set; }
public DateTime DOB { get; set; }
}
}

OUTPUT:

You might also like