Documente Academic
Documente Profesional
Documente Cultură
RAMNIRANJAN JHUNJHUNWALA
COLLEGE (AUTONOMOUS)
Ghatkopar (W), Mumbai-400 086
Certificate
This is to certify that MR SALMAN ZAKIR SHAH of TY B.Sc. (I.T.) with Roll No: 52
class has completed the required number of experiments in the subject of ADVANCED WEB
PROGRAMMING in the Department of Information Technology during the academic year
2020-2021.
1|Page
T. Y. B. SC.I. T. ADVANCE WEB PROGRAMING JOURNAL ROLL NO.: 52
INDEX
SRNO. PRATICAL DATE
1. Working with basic C# and ASP .NET
a. Create an application that obtains four int values from the user 14-09-20
and displays the product.
b. Create an application to demonstrate string operations. 18-09-20
c. Create an application that receives the (Student Id, Student 18-09-20
Name, Course Name, Date of Birth) information from a set of
students. The application should also display the information of
all the students once the data entered.
2. Working with Object Oriented C# and ASP .NET
a. Create simple application to perform following operations 21-09-20
i. Finding factorial Value ii.
Money Conversion iii. Quadratic Equation
iv. Temperature Conversion
2|Page
a) Treeview control and datalist b) Treeview operations
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<divstyle="height: 445px">
<strong>Enter a: </strong>
<asp:TextBoxID="TextBox1"runat="server"Height="29px"style="margin-top: 9px"
Width="167px"></asp:TextBox>
<br/>
<br/>
<strong>Enter b</strong>:
<asp:TextBoxID="TextBox2"runat="server"Height="29px"
style="margin-left: 10px; margin-top: 9px"Width="167px"></asp:TextBox>
<br/>
<br/>
<strong>Enter c:</strong>
<asp:TextBoxID="TextBox3"runat="server"Height="29px"
style="margin-left: 10px; margin-top: 9px"Width="167px"></asp:TextBox>
<br/>
<br/>
<strong>Enter d :</strong>
<asp:TextBoxID="TextBox4"runat="server"Height="29px"
style="margin-left: 10px; margin-top: 9px"Width="167px"></asp:TextBox>
<br/>
<br/>
<asp:ButtonID="Button1"runat="server"Height="30px"onclick="Button1_Click"
style="margin-left: 41px"Text="Result"Width="87px"/>
<asp:ButtonID="Button2"runat="server"Height="30px"onclick="Button2_Click"
style="margin-left: 41px"Text="Reset"Width="87px"/>
<br/>
<br/>
<asp:LabelID="Label1"runat="server"Text="Display the Product "></asp:Label>
</div>
</form>
</body>
</html>
1a.aspx.cs
4|Page
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(TextBox1.Text) * Convert.ToInt32(TextBox2.Text) *
Convert.ToInt32(TextBox3.Text) * Convert.ToInt32(TextBox4.Text);
Label1.Text = "Result = " + a.ToString();
}
protectedvoid Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
}
Output:
5|Page
1.B.Create an application to demonstrate string operations.
Code:
1b.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="1b.aspx.cs"Inherits="_1b"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Enter String :
<asp:TextBoxID="TextBox1"runat="server"ontextchanged="TextBox1_TextChanged"
style="margin-left: 12px"Width="160px"></asp:TextBox>
<br/>
<br/>
<asp:ButtonID="Button1"runat="server"Text="Result"Width="59px"/>
<asp:ButtonID="Button2"runat="server"onclick="Button2_Click"
style="margin-left: 26px"Text="Reset"Width="52px"/>
<br/>
<br/>
<asp:LabelID="Label1"runat="server"Text="String Lenght : "></asp:Label>
<br/>
<br/>
<asp:LabelID="Label2"runat="server"Text="Upper String : "></asp:Label>
<br/>
<br/>
<asp:LabelID="Label3"runat="server"Text="Lower String: "></asp:Label>
<br/>
<br/>
<asp:LabelID="Label4"runat="server"Text="Reverse String : "></asp:Label>
<br/>
<br/>
<asp:LabelID="Label5"runat="server"Text="Replace 'a' by 't' in String :"></asp:Label>
<br/>
<br/>
<asp:LabelID="Label6"runat="server"Text="Index of String : "></asp:Label>
<br/>
</div>
</form>
</body>
</html>
1b.aspx.cs
using System;
using System.Collections.Generic;
6|Page
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclass_1b : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid TextBox1_TextChanged(object sender, EventArgs e)
{
string s = TextBox1.Text;
}
protectedvoid Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Label6.Text = "";
Output:
7|Page
1.C. Create an application that receives the (Student Id, Student Name, Course Name, Date of Birth)
information from a set of students. The application should also display the information of all the students
once the data entered.
Code:
Design
8|Page
.aspx file
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="_1C.WebForm1"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<strong>Student Id :</strong>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<br/>
<strong>Student Name :</strong>
<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
<br/>
<strong>Course Name :</strong>
<asp:TextBoxID="TextBox3"runat="server"></asp:TextBox>
<br/>
9|Page
<br/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Show"/>
<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="Reset"/>
<br/>
You enered :<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<br/>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
<br/>
<asp:LabelID="Label4"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
.aspx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _1C
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
}
}
OUTPUT:
10 | P a g e
11 | P a g e
PRACTICAL 02
2.Working with object oriented C# and ASP.NET
2.A. Create simple application to perform following operations
i. Finding factorial Value
Code:
Design
.aspx file:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
</form>
</body>
</html>
.aspx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
12 | P a g e
using System.Web.UI.WebControls;
publicpartialclassDefault2 : System.Web.UI.Page
{
}
Label1.Text = "Result = " + fact.ToString();
}
}
Output:
13 | P a g e
.aspx file:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default3.aspx.cs"Inherits="Default3"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<br/>
<br/>
<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="Euros"/>
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:ButtonID="Button3"runat="server"OnClick="Button3_Click"Text="British Pounds"/>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:ButtonID="Button4"runat="server"OnClick="Button4_Click"Text="Japanese Yen"/>
<asp:LabelID="Label4"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
.aspx,cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassDefault3 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
14 | P a g e
protectedvoid Button2_Click(object sender, EventArgs e)
{
curConv s = newcurConv();
double r = Convert.ToDouble(TextBox1.Text);
double rate = s.Euros(r);
Label2.Text = rate.ToString();
}
double r = Convert.ToDouble(TextBox1.Text);
double rate = s.Yen(r);
Label4.Text = rate.ToString();
}
}
publicclasscurConv
{
publicdouble Dolr(double r)
{
r = r * 0.015;
return r;
}
publicdouble Euros(double r)
{
r = r * 0.012;
return r;
}
publicdouble Pound(double r)
{
r = r * 0.011;
return r;
}
publicdouble Yen(double r)
{
r = r * 1.64;
return r;
}
}
Output:
15 | P a g e
iii. Quadratic Equation
Code:
Deign
.aspx file:
<
%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="WebApplication1.WebFor
m1"%>
16 | P a g e
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
Quadratic Equation : ax^2 + bx+c=0 where a,b,c are known value, x is variable or
unknown<br/>
<br/>
Enter a : <asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<br/>
<br/>
Enter b :
<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
<br/>
<br/>
Enter c :
<asp:TextBoxID="TextBox3"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Result"/>
<asp:ButtonID="Button2"runat="server"Text="Reset"/>
<br/>
<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:LabelID="Label2"runat="server"></asp:Label>
<asp:LabelID="Label3"runat="server"></asp:Label>
</form>
</body>
</html>
.aspx,cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
publicvoid demo()
{
double a, b, c, r1, r2, x;
double det;
a = Convert.ToInt32(TextBox1.Text);
17 | P a g e
b = Convert.ToInt32(TextBox2.Text);
c = Convert.ToInt32(TextBox3.Text);
det = (b * b) - (4 * a * c);
if (det > 0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
r2 = (-b - x) / (2 * a);
Label1.Text = "There are two roots ::";
Label2.Text = r1.ToString();
Label3.Text = r2.ToString();
}
elseif (det == 0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
Label1.Text = "There is only one root ::";
Label2.Text = r1.ToString();
}
else
{
Label1.Text = "There is no root!!!";
}
18 | P a g e
iv. Temperature Conversion
Code:
Design
.aspx file:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="2a_iv.aspx.cs"Inherits="_2a_iv"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
 
;
Temparature Conversion<br/>
<br/>
Enter Value Celsius :
<asp:TextBoxID="TextBox1"runat="server"style="margin-left: 33px"></asp:TextBox>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Celsius to
Fahrenheit"Width="200px"/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
0^F<br/>
<br/>
19 | P a g e
Enter Value Fahrenheit :
<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="Fahrenheit to Celsius
"Width="200px"/>
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
0^C</div>
</form>
</body>
</html>
.aspx,cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassWebForm2 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
publicclasstempConv
{
publicdouble ctof(double temp)
{
temp = 9.0 / 5.0 * temp + 32;
return temp;
}
publicdouble ftoc(double temp)
{
temp = (temp - 32) * 5 / 9;
return temp;
}
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
tempConv s = newtempConv();
double n = Convert.ToDouble(TextBox1.Text);
double x = s.ctof(n);
Label1.Text = x.ToString();
20 | P a g e
Output:
2B.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Function Overloading<br/>
<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
21 | P a g e
<br/>
<br/>
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
<br/>
</div>
</form>
</body>
</html>
2B.1aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassDefault2 : System.Web.UI.Page
{
publicint add(int a)
{
return a + a;
}
}
}
Output
22 | P a g e
B. Inheritance
1.single inheritance
2.1Aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default3.aspx.cs"Inherits="Default3"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
</form>
23 | P a g e
</body>
</html>
2.1Aspx cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassDefault3 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
publicclassA
{
publicint sqr(int a)
{
return a + a;
}
}
publicclassB : A
{
publicint cub(int a)
{
int b = sqr(a);
return b + a;
}
}
}
}
Output
2. Multilevel Inheritance
24 | P a g e
2.2Aspx
%@PageLanguage="C#"AutoEventWireup="true"CodeFile="multi.aspx.cs"Inherits="multi"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Enter Number:<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Result"/>
<br/>
<br/>
Number is power of 2:<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
Number is power of 3:<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
Number is power of 4:<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
2.2 Aspx cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassmulti : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
publicclassA
25 | P a g e
{
publicint pow2(int a)
{
return a * a;
}
}
publicclassB : A
{
publicint pow3(int a)
{
int b = pow2(a);
return b * a;
}
}
publicclassC : B
{
publicint pow4(int a)
{
int c = pow3(a);
return c * a;
}
}
}
}
Output
3.Hierarchical inheritance
26 | P a g e
3Aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="hierarchical.aspx.cs"Inherits="hierarchical"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Enter a:<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<br/>
<br/>
Enter b:<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Result"/>
<br/>
<br/>
a+b=<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
a-b=<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
3Aspxcs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclasshierarchical : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
27 | P a g e
{
}
publicclassA
{
publicint a;
publicint b;
}
publicclassB : A
{
publicclassC : A
{
}
}
Output
C. Constructor Overloading
28 | P a g e
2B Aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="constructor.aspx.cs"Inherits="constructor"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Constructor Overloading<br/>
<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
2B Aspx cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassconstructor : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
add obj1 = newadd(2);
add obj2 = newadd(2, 3);
add obj3 = newadd(2, 3, 4);
Label1.Text = obj1.r.ToString();
Label2.Text = obj2.r.ToString();
Label3.Text = obj3.r.ToString();
}
publicclassadd
{
publicint r;
public add(int a)
{
29 | P a g e
r = a + a;
}
public add(int a, int b)
{
r = a + b;
}
public add(int a, int b, int c)
{
r = a + b + c;
}
}
Output
2B aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
</form>
</body>
</html>
2B aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassDefault2 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
Rect r1 = newRect();
double x = r1.show(3, 4);
Circle c1 = newCircle();
double y = c1.show(3, 4);
Label1.Text = x.ToString();
Label2.Text = y.ToString();
}
}
interfaceArea
{
double show(double s, double t);
}
classRect : Area
{
publicdouble show(double s, double t)
{
return s * t;
}
}
classCircle : Area
{
publicdouble show(double s, double t)
{
return (3.14 * s * s);
}
}
Output
31 | P a g e
2.C.Create simple application to demonstrate use of following concepts
i. Using Delegates and events ii. Exception handling
Code:
A. Using Delegate and Events
2C 1aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Delegate.aspx.cs"Inherits="Delegate"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
</form>
</body>
</html>
2C 1aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
32 | P a g e
publicpartialclassDelegate : System.Web.UI.Page
{
publicdelegatestringdele();
publicstaticstring display1()
{
string s1 = "Hema";
return s1;
}
publicstaticstring display2()
{
string s2 = "Nalawade";
return s2;
}
}
}
Output
A. Exception Handling
2c 2aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
33 | P a g e
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
</form>
</body>
</html>
2C 2aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
catch (System.IndexOutOfRangeException ex)
{
Label1.Text = ex.ToString();
}
}
}
Output:
34 | P a g e
PRACTICAL 03
3. Working with Web Forms and Controls
3.A. Create a simple web page with various sever controls to demonstrate setting and use of their
properties. (Example : AutoPostBack)
Code:
Webform.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="WebApplication1.WebForm1"%>
35 | P a g e
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ListBoxID="ListBox1"runat="server"OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>Python</asp:ListItem>
<asp:ListItem>JAVA</asp:ListItem>
</asp:ListBox>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Show"/>
<asp:TextBoxID="TextBox1"runat="server"Height="36px"TextMode="MultiLine"Width="131px"></asp:TextBox>
<br/>
<asp:LabelID="Label1"runat="server"Text="Select Color:"></asp:Label>
<asp:RadioButtonID="RadioButton1"runat="server"OnCheckedChanged="RadioButton1_CheckedChanged"Text="Red"/>
<asp:RadioButtonID="RadioButton2"runat="server"OnCheckedChanged="RadioButton2_CheckedChanged"Text="Green"/>
<asp:RadioButtonID="RadioButton3"runat="server"OnCheckedChanged="RadioButton3_CheckedChanged"Text="Blue"/>
<br/>
<asp:LabelID="Label2"runat="server"Text="SelectSpecial Formatting:"></asp:Label>
<asp:CheckBoxID="CheckBox1"runat="server"OnCheckedChanged="CheckBox1_CheckedChanged"Text="Bold"/>
<asp:CheckBoxID="CheckBox2"runat="server"OnCheckedChanged="CheckBox2_CheckedChanged"Text="Italic"/>
<asp:CheckBoxID="CheckBox3"runat="server"Text="Underline"/>
<br/>
<asp:LabelID="Label3"runat="server"Text="Select Size:"></asp:Label>
<asp:DropDownListID="DropDownList1"runat="server"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItemValue="18"></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br/>
<asp:LabelID="Label4"runat="server"Text="Select Name"></asp:Label>
<asp:DropDownListID="DropDownList2"runat="server"OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItemValue="Snow"></asp:ListItem>
<asp:ListItem>Sneha</asp:ListItem>
<asp:ListItem>Prachi</asp:ListItem>
<asp:ListItem>soni</asp:ListItem>
<asp:ListItem>Hema</asp:ListItem>
<asp:ListItem>Zoya</asp:ListItem>
</asp:DropDownList>
<br/>
</div>
</form>
</body>
</html>
Webform.aspx.cs
using System;
namespace WebApplication1
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
36 | P a g e
protectedvoid Page_Load(object sender, EventArgs e)
{
{
if (!IsPostBack)
{
string str = "Best Friend";
if (ViewState["name"] == null)
{
ViewState["name"] = str;
}
}
}
}
TextBox1.Text = "";
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{
TextBox1.Text = TextBox1.Text + "" + ListBox1.Items[i].Text + "\n";
}
}
37 | P a g e
Label2.Font.Bold = true;
}
Output:
Code:
webform.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="calender.WebForm1"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:CalendarID="Calendar1"runat="server"BackColor="#FFFFCC"BorderColor="#FFCC66"BorderWidth="1px"Font-
Names="Verdana"Font-
Size="8pt"ForeColor="#663399"Height="267px"Width="371px"DayNameFormat="Shortest"ShowGridLines="True">
<DayHeaderStyleFont-Bold="True"BackColor="#FFCC66"Height="1px"/>
<NextPrevStyleFont-Size="9pt"ForeColor="#FFFFCC"/>
<OtherMonthDayStyleForeColor="#CC9966"/>
<SelectedDayStyleBackColor="#CCCCFF"Font-Bold="True"/>
<SelectorStyleBackColor="#FFCC66"/>
38 | P a g e
<TitleStyleBackColor="#990000"Font-Bold="True"Font-Size="9pt"ForeColor="#FFFFCC"/>
<TodayDayStyleBackColor="#FFCC66"ForeColor="White"/>
</asp:Calendar>
<br/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Result"/>
<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="Reset"/>
<br/>
<br/>
your selected date : <asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
Today's Date :
<asp:LabelID="Label2"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
Ganpati Vacation Start :
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
Days Remaining For Ganpati Vacation :
<asp:LabelID="Label4"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
Days remaining for new year :
<asp:LabelID="Label5"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
webform.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace calender
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
Label1.Text = Calendar1.SelectedDate.Date.ToString();
Label2.Text = Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "2-9-2019";
TimeSpan d = new DateTime(2019, 9, 2) - DateTime.Now;
Label4.Text = d.Days.ToString();
TimeSpan d1 = new DateTime(2019, 12, 31) - DateTime.Now;
39 | P a g e
Label5.Text = d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "2-9-2019")
Label3.Text = "<b>Ganpati Festival start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "11-9-2019")
Label3.Text = "<b>Ganpati Festival end</b>";
}
}
if (e.Day.Date.Day == 2 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2019, 9, 11);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate, Calendar1.SelectedDate.AddDays(10));
Label b = new Label();
e.Cell.Controls.Add(b);
}
}
}
}
}
Output:
40 | P a g e
3.C.Demonstrate the use of Treeview control perform following operations.
Code:
XMLfile1.xml
<?xmlversion="1.0"encoding="utf-8" ?>
<studentdetail>
<student>
<sid>1</sid>
<sname>Tushar</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>2</sid>
<sname>Sonali</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>3</sid>
<sname>Yashashree</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>4</sid>
<sname>Vedshree</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>
Webform.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="_8b.WebForm1"%>
<!DOCTYPEhtml>
41 | P a g e
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Treeview control navigation:<asp:TreeViewID="TreeView1"runat="server"Width=
"150px"ImageSet="Arrows">
<HoverNodeStyleFont-Underline="True"ForeColor="#5555DD"/>
<Nodes>
<asp:TreeNodeText="ASP.NET Practs"Value="New Node">
<asp:TreeNodeText="Calendar Control"Value="RED"NavigateUrl="~/calndrCtrl.aspx">
</asp:TreeNode>
<asp:TreeNodeText="Constructor Overloading"Value="GREEN"
NavigateUrl="~/clsconstrc.aspx"></asp:TreeNode>
<asp:TreeNodeNavigateUrl="~/singleInh.aspx"Text="Inheritance"
Value="BLUE"></asp:TreeNode>
<asp:TreeNodeNavigateUrl="~/clsProp.aspx"Text="Class Properties"Value="Class
Properties"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
<NodeStyleFont-Names="Tahoma"Font-Size="10pt"ForeColor="Black"
HorizontalPadding="5px"NodeSpacing="0px"VerticalPadding="0px"/>
<ParentNodeStyleFont-Bold="False"/>
<SelectedNodeStyleFont-Underline="True"ForeColor="#5555DD"
HorizontalPadding="0px"VerticalPadding="0px"/>
</asp:TreeView>
<br/>
Fetch Datalist Using XML data : </div>
<asp:DataListID="DataList1"runat="server">
<ItemTemplate>
<tableclass="table"border="1">
<tr>
<td>Roll Num : <%# Eval("sid") %><br/>
Name : <%# Eval("sname") %><br/>
Class : <%# Eval("sclass")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</body>
</form>
</html>
Webform.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _3c
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
42 | P a g e
if (!IsPostBack)
{
BindData();
}
}
protectedvoid BindData()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile1.xml"));
if (ds != null&& ds.HasChanges())
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataBind();
}
}
}
}
Output:
43 | P a g e
PRACTICAL 04
4.Working with Form Controls
4.A.
Code:
Design:
44 | P a g e
WebForm1.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="_4apract.WebForm1"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<fieldsetstyle="width:280px">
<legend>Registration Form</legend>
<table>
<tr>
<td>First Name:</td><td><asp:textboxid="txt1"runat="server"></asp:textbox></td>
<td><asp:RequiredFieldValidatorID="validfname"runat="server"ControlToValidate="txt1"ErrorMessage="Requ
ired!"ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Last Name:</td><td><asp:textboxid="txt2"runat="server"></asp:textbox></td>
<td><asp:RequiredFieldValidatorID="validlname"runat="server"ControlToValidate="txt2"ErrorMessage="Requ
ired!"ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>User Name:</td><td><asp:textboxid="user"runat="server"></asp:textbox></td>
<td><asp:RequiredFieldValidatorID="validuser"runat="server"
ControlToValidate="user"ErrorMessage="Required!"ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Password:</td><td><asp:textboxID="pwd"runat="server"TextMode="Password"></asp:textbox></td>
45 | P a g e
<td><asp:RequiredFieldValidatorID="validpwd"runat="server"ControlToValidate="pwd"ErrorMessage="Require
d!"ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Confirm
Password:</td><td><asp:textboxID="Textbox1"runat="server"TextMode="Password"></asp:textbox></td>
</tr>
<tr>
<td>Email:</td><td><asp:TextBoxID="email"runat="server"TextMode="Email"></asp:TextBox></td>
<td><asp:RequiredFieldValidatorID="validemail"runat="server"ControlToValidate="email"ErrorMessage="req
uired!"ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Mobile:</td><td><asp:TextBoxID="mobile"runat="server"TextMode="Phone"></asp:TextBox></td>
</tr>
<tr>
<td>Gender:</td><td><asp:RadioButtonListID="RadioButtonList1"runat="server">
<asp:ListItemText="Male"Value="0"></asp:ListItem>
<asp:ListItemText="Female"Value="1"></asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td>DOB: </td><td><asp:TextBoxID="dob"runat="server"TextMode="Date"Width="168px"></asp:TextBox></td>
<td><asp:RequiredFieldValidatorID="validdob"runat="server"ControlToValidate="dob"ErrorMessage="Require
d"ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Course:
</td><td><asp:DropDownListID="ddlCourse"runat="server"datavaluefield="Course"Width="173px">
<asp:ListItemtext="Select Course"Value="-1"></asp:ListItem>
<asp:ListItemText="BTech"Value="0"></asp:ListItem>
<asp:ListItemText="MCA"Value="1"></asp:ListItem>
<asp:ListItemText="MBA"Value="2"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:RequiredFieldValidatorInitialValue="-
1"ID="validcourse"runat="server"ControlToValidate="ddlCourse"ErrorMessage="Required!"ForeColor="Red"><
/asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Nationality:</td><td><asp:CheckBoxID="check"Text="Indian"runat="server"/><asp:CheckBoxid="checkNat
"Text="Others"runat="server"/></td>
</tr>
<tr>
<td>Profile: </td><td><asp:Imageid="img"ImageUrl="images/new/new-member.png"runat="server"/></td>
</tr>
<tr>
<td></td><td><asp:FileUploadID="imgupload"runat="server"Enabled="true"/></td>
</tr>
<tr>
<td><asp:ButtonID="btn1"runat="server"Text="Submit"></asp:Button></td>
<td><asp:ButtonID="btn2"runat="server"Text="Reset"></asp:Button></td>
</tr>
</table>
</fieldset>
</form>
</body>
Output:
46 | P a g e
Registration page having various web controls
47 | P a g e
Filling the record
48 | P a g e
4.B.Create Web Form to demonstrate use of Adrotator Control.
Add a XML File , name it “adds.xml”
Default.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<br/>
<asp:TimerID="Timer1"runat="server">
</asp:Timer>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<Triggers>
<asp:AsyncPostBackTriggerControlID="Timer1"EventName="Tick"/>
</Triggers>
<ContentTemplate>
<asp:AdRotatorID="AdRotator1"runat="server"AdvertisementsFile="~/adds.xml"
Height="200px"Width="200px"DataSourceID="XmlDataSource1"ImageUrlField=""/>
<asp:XmlDataSourceID="XmlDataSource1"runat="server"DataFile="~/adds.xml"
TransformFile="~/After.jpg">
</asp:XmlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Design:
49 | P a g e
4.C.Create Web Form to demonstrate use User Controls.
Code:
4c.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<%@RegisterSrc="~/footer.ascx"TagName="footer"TagPrefix="STfooter"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
</div>
<STfooter:footerID="footer1"runat="server"/>
</form>
</body>
</html>
50 | P a g e
Footer.ascx
<%@ControlLanguage="C#"AutoEventWireup="true"CodeFile="footer.ascx.cs"Inherits="footer"%>
<table>
<tr>
<tdalign="center"style="font-family:Cambria; background-color:#00CCFF;font-size: 14px; text-decoration;
color: #FF0000; font-weight:bold;">
S. M. Shetty College of Powai</td>
</tr></table>
Output:
PRACTICAL 05
5.Working with Navigation, Beautification and Master page.
5.A.Create Web Form to demonstrate use of Website Navigation controls and Site Map.
Code:
Web.sitemap
51 | P a g e
<?xmlversion="1.0"encoding="utf-8" ?>
<siteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNodeurl="prac5a.aspx"title="Home"description="Homepage of our website">
<siteMapNodeurl="clsProp.aspx"title="Page2"description="Page2" />
<siteMapNodeurl="Default2.aspx"title="Page3"description="Page3" />
<siteMapNodeurl="Default3.aspx"title="Page4"description="Page4" />
</siteMapNode>
</siteMap>
Default 3.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default3.aspx.cs"Inherits="clsProp"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:MenuID="Menu1"runat="server">
<Items>
<asp:MenuItemNavigateUrl="~/5A.sitemap"Text="Home"Value="Home">
<asp:MenuItemNavigateUrl="~/5A.sitemap"Text="Page 3"Value="Page 3">
</asp:MenuItem>
</asp:MenuItem>
<asp:MenuItemNavigateUrl="~/5A.sitemap"Text="Home"Value="Home">
</asp:MenuItem>
</Items>
</asp:Menu>
<asp:SiteMapDataSourceID="SiteMapDataSource1"runat="server"
StartingNodeUrl="~/5A.sitemap"/>
</div>
</form>
</body>
</html>
52 | P a g e
Output:
5.B.Create a web application to demonstrate use of Master Page with applying Styles and Themes for
page beautification.
Code:
SkinFile.skin
<asp:Labelrunat="server"ForeColor="red"Font-Size="14pt"Font-Names="Verdana"/>
<asp:buttonrunat="server"Borderstyle="Solid"Borderwidth="2px"Bordercolor="Blue"Backcolor="Orange"/>
demostyle.css
body
{
background-color:Lime;
font-family:Cambria;
font-size:18px;
}
MasterPage.master
<
%@MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs"Inherits="MasterPage"
%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<asp:ContentPlaceHolderid="head"runat="server">
</asp:ContentPlaceHolder>
<linkhref="demostyle.css"rel="Stylesheet"type="text/css"/>
53 | P a g e
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ContentPlaceHolderid="ContentPlaceHolder1"runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolderid="ContentPlaceHolder2"runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
demo.aspx
<%@PageTheme=""Title=""Language="C#"MasterPageFile="~/MasterPage.master"
AutoEventWireup="true"CodeFile="demo.aspx.cs"Inherits="demo"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"runat="server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="ContentPlaceHolder1"runat="server">
<asp:LabelID="Label1"runat="server"Text="S.M.Shetty College of Powai"></asp:Label>
</asp:Content>
<asp:ContentID="Content3"ContentPlaceHolderID="ContentPlaceHolder2"runat="server">
<br/><br/>
<asp:LabelID="Label2"runat="server"Text="TYBsc IT"></asp:Label>
<br/><br/>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label><br/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Demo"/>
</asp:Content>
Demo.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassdemo : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
Label3.Text = "Class :TYIT B -Prachita Mhatre";
}
}
54 | P a g e
Output:
1. View State:
Code:
.aspx file:
.aspx,cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassWebForm5 : System.Web.UI.Page
{
privateobject blaSt;
2.Query String:
Code:
WebForm1.aspx
.aspx,cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
56 | P a g e
protectedvoid Page_Load(object sender, EventArgs e)
{
WebForm2.aspx
.aspx,cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
publicpartialclassWebForm2 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblUserId.Text = Request.QueryString["UserId"];
lblUserName.Text = Request.QueryString["UserName"];
}
}
}
}
Input:
57 | P a g e
3.Cookies:
Code:
.aspx file:
<
%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="WebApplication1.WebFor
m1"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Cookies</title>
</head>
<bodyrunat="server"id="BodyTag">
<formid="form1"runat="server">
<asp:DropDownListrunat="server"id="ColorSelector"autopostback="true"onselectedindexchanged="ColorSelec
tor_IndexChanged">
<asp:ListItemvalue="White"selected="True">Select color...</asp:ListItem>
<asp:ListItemvalue="Red">Red</asp:ListItem>
<asp:ListItemvalue="Green">Green</asp:ListItem>
<asp:ListItemvalue="Blue">Blue</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
.aspx,cs file:
using System;
58 | P a g e
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["BackgroundColor"] != null)
{
ColorSelector.SelectedValue = Request.Cookies["BackgroundColor"].Value;
BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
}
}
protectedvoid ColorSelector_IndexChanged(object sender, EventArgs e)
{
BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
HttpCookie cookie = newHttpCookie("BackgroundColor");
cookie.Value = ColorSelector.SelectedValue;
cookie.Expires = DateTime.Now.AddHours(1);
Response.SetCookie(cookie);
}
}
}
Output:
59 | P a g e
4.Session and Application State:
Global.asax:
<%@ApplicationLanguage="C#"%>
<scriptrunat="server">
60 | P a g e
{
// Code that runs when a new session is started
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
</script>
Web.config:
<?xmlversion="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>
<sessionStatemode="InProc"cookieless="false"timeout="1"/>
<compilationdebug="true"targetFramework="4.5" />
<httpRuntimetargetFramework="4.5" />
</system.web>
</configuration>
Default.asax:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="4.aspx.cs"Inherits="_4"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
Visitors Count :<%=Application["OnlineUsers"].ToString() %>
</div>
</form>
</body>
</html>
Output:
61 | P a g e
PRACTICAL 06
6.A.Create a web application bind data in a multiline textbox by querying in another textbox.
1. Create a webpage with one Button, one Multiline TextBox and one list box with
setting TextMode Property of text box to Multiline as shown below.
62 | P a g e
2. Write the Database related code in code behind C# file as given below.
Note: The users have to use their own system connection string in place of connection string
given in following code.
The connection string is available in Server Explorer (Right click on Database Name and Select
Properties) as displayed below. User can copy this connection string and can use in code.
63 | P a g e
3. Add this string to configuration file (web.config) as given below.
Web.confing
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\tushars\Documents\Visual Studio
2015\WebSites\Workshop\App_Data\Database.mdf';Integrated Security=True" />
</connectionStrings>
</configuration>
4. Now use the following code C# in Default.aspx.cs (Note : First write following using
statements at the top of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class DataBinding : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
64 | P a g e
SqlConnection con = new SqlConnection(connStr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text, con);
SqlDataReader reader = cmd.ExecuteReader();
ListBox1.Items.Clear();
while (reader.Read())
{
//To add new blank line in the text area
for (int i = 0; i < reader.FieldCount - 1; i++)
{
ListBox1.Items.Add(reader[i].ToString());
}
}
reader.Close();
con.Close();
}
}
Output:
65 | P a g e
Add the following code on Button click event in C# Code behind file.
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select City, State from Customer", con);
con.Open();
while (reader.Read())
{
Label1.Text += reader["City"].ToString() + " " + reader["State"].ToString() +
"<br>";
}
reader.Close();
con.Close();
}
Output:
1. Drag the Datalist control to our web page form toolbox->Data-> Datalist.
2. Then select Choose Data Source Option and select <New Data Source>.
66 | P a g e
3. Now Select SQL Database from options and Click Ok button.
67 | P a g e
10. Once the Connection is made then click on Next button from Data Source Wizard.
11. Then wizard ask for saving the connection string in configuration file. If you already
stored it web.config file then uncheck check box, if you haven’t, then select the
checkbook. Then click on next button.
12. The next screen gives option to configure the select statement. Here we can choose
the table as well as configure the select statement as we need to display the data on
web page.
68 | P a g e
13. In next screen we can test our query to check the output. Then Click on finish.
After successful steps form the Datalist controls option wizard our web page design and
output will look like following.
Output:
69 | P a g e
70 | P a g e
PRACTICAL 07
7.Working with Database
7.a.Create a web application to display Databinding using Dropdownlist control.
Code:
Design
7a aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassDrop1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
string connStr=
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select Distinct City from Customer", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "City";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
71 | P a g e
}
}
Output
7B aspx. cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclass_Default : System.Web.UI.Page
{
publicobject box1 { get; privateset; }
ListBox1.DataTextField = "City";
ListBox1.DataValueField = "POSTAL_CODE";
ListBox1.DataBind();
reader.Close();
con.Close();
}
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
Label1.Text = ListBox1.SelectedValue;
}
}
Output
7.C.Create a web application for inserting and deleting record from a database.
(UsingExecute-Non Query).
Code:
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;
using System.Data.SqlClient;
using System.Configuration;
publicpartialclassExecuteNonQuery : System.Web.UI.Page
{
protectedvoid Button1_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = newSqlConnection(connStr);
string InsertQuery = "insert into BRANCH values(@ADDRESS, @CITY, @NAME, @STATE,
@ZIP_CODE)";
SqlCommand cmd = newSqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@ADDRESS", TextBox1.Text);
73 | P a g e
cmd.Parameters.AddWithValue("@CITY", TextBox2.Text);
cmd.Parameters.AddWithValue("@NAME", TextBox3.Text);
cmd.Parameters.AddWithValue("@STATE", TextBox4.Text);
cmd.Parameters.AddWithValue("@ZIP_CODE", TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Inserted Successfuly.";
con.Close();
}
protectedvoid Button2_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = newSqlConnection(connStr);
string InsertQuery = "delete from branch where NAME=@NAME";
SqlCommand cmd = newSqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@NAME", TextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Deleted Successfuly.";
con.Close();
}
}
Output:
74 | P a g e
PRACTICAL 08
8.Working with data controls
8.A.Create a web application to demonstrate various uses and properties of SqlDataSource.
Code:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head><body>
75 | P a g e
<asp:Parameter Name="class" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="class" Type="String"/>
WebFile.xml
<?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="ConnectionString" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Databas
e.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
</configuration>
Default.aspx.cs
76 | P a g e
using System;
using System.Collections.Generic; using
System.Linq; using System.Web; using
System.Web.UI;
using System.Web.UI.WebControls; using
System.Data; using System.Data.SqlClient; using
System.Configuration; public partial class _Default :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString =
Output:
Insert: Delete :
77 | P a g e
8.B.Create a web application to demonstrate data binding using DetailsView and FormViewControl.
Code:
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 align="center">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [student]"
ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [student] WHERE [id] =
@original_id AND (([name] = @original_name) OR ([name] IS NULL AND @original_name IS
NULL))" InsertCommand="INSERT INTO [student] ([id], [name]) VALUES (@id, @name)"
OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [student] SET [name]
= @name WHERE [id] = @original_id AND (([name] = @original_name) OR ([name] IS NULL AND
@original_name IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
78 | P a g e
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name"/>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView><br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [student]"
<br />name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>'
/><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
79 | P a g e
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
id:<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' /><br
/>name:<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>'
/><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
Design.as
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){ } }
Output:
80 | P a g e
8.C.Create a web application to display Using Disconnected Data Access and Databinding using
GridView.
Code:
XMLFile.xml
<?xmlversion="1.0"encoding="utf-8" ?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilationdebug="true"targetFramework="4.5" />
<httpRuntimetargetFramework="4.5" />
</system.web>
<connectionStrings>
<addname="connStr"connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=
'C:\practical_in_c#\WebSite4\App_Data\Database.mdf';Integrated Security=True"/>
</connectionStrings>
</configuration>
Webform1.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="_8c.WebForm1"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
</div>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Show Disconnected Fetched Data"/>
<br/>
<br/>
<asp:GridViewID="GridView1"runat="server"DataSourceID="SqlDataSource1">
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"></asp:SqlDataSource>
</form>
</body>
</html>
Webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
81 | P a g e
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _8c
{
publicpartialclassWebForm1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
}
PRACTICAL 09
9.Working with GridView control
9.A.Create a web application to demonstrate use of GridView control template and GridView
hyperlink.
Code:
Design:
82 | P a g e
9a.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="9a.aspx.cs"Inherits="_9a"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"BackColor="White"BorderColor="#3366CC"BorderStyle="
None"BorderWidth="1px"CellPadding="4"DataKeyNames="Id"DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundFieldDataField="Id"HeaderText="Id"ReadOnly="True"SortExpression="Id"/>
<asp:BoundFieldDataField="FirstName"HeaderText="FirstName"SortExpression="FirstName"/>
<asp:BoundFieldDataField="LastName"HeaderText="LastName"SortExpression="LastName"/>
<asp:BoundFieldDataField="City"HeaderText="City"SortExpression="City"/>
<asp:BoundFieldDataField="Country"HeaderText="Country"SortExpression="Country"/>
<asp:BoundFieldDataField="Phone"HeaderText="Phone"SortExpression="Phone"/>
</Columns>
<FooterStyleBackColor="#99CCCC"ForeColor="#003399"/>
<HeaderStyleBackColor="#003399"Font-Bold="True"ForeColor="#CCCCFF"/>
<PagerStyleBackColor="#99CCCC"ForeColor="#003399"HorizontalAlign="Left"/>
<RowStyleBackColor="White"ForeColor="#003399"/>
<SelectedRowStyleBackColor="#009999"Font-Bold="True"ForeColor="#CCFF99"/>
<SortedAscendingCellStyleBackColor="#EDF6F6"/>
<SortedAscendingHeaderStyleBackColor="#0D4AC4"/>
<SortedDescendingCellStyleBackColor="#D6DFDF"/>
<SortedDescendingHeaderStyleBackColor="#002876"/>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString
%>"SelectCommand="SELECT DISTINCT * FROM [Customer]"></asp:SqlDataSource>
</form>
</body>
</html>
Output:
83 | P a g e
9.B.Create a web application to demonstrate use of GridView button column and GridViewevents.
Code:
Design :
84 | P a g e
9b.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="9b.aspx.cs"Inherits="_9b"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:GridViewID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"BackColor="White"
BorderColor="#CC9966"BorderStyle="None"BorderWidth="1px"CellPadding="4"DataKeyNames="Id"DataSourceID="SqlDataSource1"
>
<Columns>
<asp:BoundFieldDataField="Id"HeaderText="Id"ReadOnly="True"SortExpression="Id"/>
<asp:BoundFieldDataField="FirstName"HeaderText="FirstName"SortExpression="FirstName"/>
<asp:BoundFieldDataField="LastName"HeaderText="LastName"SortExpression="LastName"/>
<asp:BoundFieldDataField="City"HeaderText="City"SortExpression="City"/>
<asp:BoundFieldDataField="Country"HeaderText="Country"SortExpression="Country"/>
<asp:BoundFieldDataField="Phone"HeaderText="Phone"SortExpression="Phone"/>
<asp:CommandFieldButtonType="Button"HeaderText="Edit"ShowEditButton="True"ShowHeader="True"/>
<asp:CommandFieldButtonType="Button"HeaderText="Delete"ShowDeleteButton="True"ShowHeader="True"/>
</Columns>
<FooterStyleBackColor="#FFFFCC"ForeColor="#330099"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="#FFFFCC"/>
<PagerStyleBackColor="#FFFFCC"ForeColor="#330099"HorizontalAlign="Center"/>
<RowStyleBackColor="White"ForeColor="#330099"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="#663399"/>
<SortedAscendingCellStyleBackColor="#FEFCEB"/>
<SortedAscendingHeaderStyleBackColor="#AF0101"/>
<SortedDescendingCellStyleBackColor="#F6F0C0"/>
<SortedDescendingHeaderStyleBackColor="#7E0000"/>
</asp:GridView>
85 | P a g e
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT * FROM [Customer]"UpdateCommand="UPDATE Customer SET FirstName=@FirstName,
LastName=@LastName,City=@City,Country=@Country,Phone=@Phone Where Id=@Id">
<UpdateParameters>
<asp:ParameterName="Id"Type="Int32"/>
<asp:ParameterName="FirstName"Type="String"/>
<asp:ParameterName="LastName"Type="String"/>
<asp:ParameterName="City"Type="String"/>
<asp:ParameterName="Country"Type="String"/>
<asp:ParameterName="Phone"Type="String"/>
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
Output:
86 | P a g e
9.C.Create a web application to demonstrate GridView paging and Creating own table format using
GridView.
Code:
Design :
9c.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="9c.aspx.cs"Inherits="_9c"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:GridViewID="GridView1"runat="server"BackColor="White"BorderColor="#CC9966"BorderStyle="None"BorderWidth="1px"Cell
Padding="4"OnPageIndexChanging="GridView1_PageIndexChanging"OnSorting="GridView1_Sorting">
<FooterStyleBackColor="#FFFFCC"ForeColor="#330099"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="#FFFFCC"/>
<PagerStyleBackColor="#FFFFCC"ForeColor="#330099"HorizontalAlign="Center"/>
<RowStyleBackColor="White"ForeColor="#330099"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="#663399"/>
<SortedAscendingCellStyleBackColor="#FEFCEB"/>
<SortedAscendingHeaderStyleBackColor="#AF0101"/>
<SortedDescendingCellStyleBackColor="#F6F0C0"/>
87 | P a g e
<SortedDescendingHeaderStyleBackColor="#7E0000"/>
</asp:GridView>
</form>
</body>
</html>
9c.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;
publicpartialclass_9c : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DemostrateDataView();
}
}
privatevoid DemostrateDataView()
{
DataTable myTable = newDataTable();
DataColumn colItem1 = newDataColumn("Id", Type.GetType("System.Int32"));
DataColumn colItem2 = newDataColumn("Name", Type.GetType("System.String"));
DataColumn colItem3 = newDataColumn("Price", Type.GetType("System.String"));
myTable.Columns.Add(colItem1);
myTable.Columns.Add(colItem2);
myTable.Columns.Add(colItem3);
DataRow NewRow;
for (int i = 0; i < 50; i++)
{
NewRow = myTable.NewRow();
NewRow["Id"] = i;
NewRow["Name"] = "product" + i;
NewRow["Price"] = (20 * (i + 1));
myTable.Rows.Add(NewRow);
}
GridView1.DataSource = myTable;
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
ViewState["dataTable"] = myTable;
ViewState["sortdr"] = "Asc";
GridView1.DataBind();
}
protectedvoid GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
DemostrateDataView();
}
protectedvoid GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtrslt = (DataTable)ViewState["dataTable"];
if (dtrslt.Rows.Count > 0)
{
if (Convert.ToString(ViewState["sortdr"]) == "Asc")
88 | P a g e
{
dtrslt.DefaultView.Sort = e.SortExpression + "Desc";
ViewState["sortdr"] = "Desc";
}
else
{
dtrslt.DefaultView.Sort = e.SortExpression + "Asc";
ViewState["sortdr"] = "Asc";
}
GridView1.DataSource = dtrslt;
GridView1.DataBind();
}
}
}
Output:
89 | P a g e
PRACTICAL 10
10.Working with AJAX and XML
10.A.Create a web application to demonstrate reading and writing operation with XML.
Code:
Design:
90 | P a g e
10a.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="10a.aspx.cs"Inherits="_10a"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
<br/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="XML Writer"/>
<br/>
<br/>
<asp:ListBoxID="ListBox1"runat="server"Height="361px"Width="538px"></asp:ListBox>
<br/>
<br/>
<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="XML Reader"/>
</form>
</body>
</html>
10a.aspx.cs
using System;
using System.Collections.Generic;
91 | P a g e
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
publicpartialclass_10a : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
caseXmlNodeType.Text:
ListBox1.Items.Add(xReader.Value);
break;
caseXmlNodeType.EndElement:
ListBox1.Items.Add("</" + xReader.Name + ">");
break;
}
}
}
}
demo.aspx
<?xmlversion="1.0"?>
Output:
92 | P a g e
After you check your Demo.xml look like below:
<Details><ID>1</ID><FirstName>Deepa</FirstName><LastName>Varma</LastName><Salary>50000</Salary></Details>
10.B. Create a web application to demonstrate Form Security and Windows Security withproper
Authentication and Authorization properties.
Code:
Design:
loginPage.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="loginPage.aspx.cs"Inherits="loginPage"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
93 | P a g e
<formid="form1"runat="server">
<div>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
<br/>
<asp:ButtonID="Login"runat="server"OnClick="Button1_Click"Text="Login"/>
<br/>
<br/>
<asp:CheckBoxID="CheckBox1"runat="server"OnCheckedChanged="CheckBox1_CheckedChanged"Text="Check here if it is not a
public computer"/>
</div>
</form>
</body>
</html>
loginPage.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.Web.Security;
publicpartialclassloginPage : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedbool authenticate(String uname, String pass)
{
if (uname == "Yash")
{
if (pass == "yash123")
returntrue;
}
if (uname == "ved")
{
if (pass == "ved123")
returntrue;
}
if (uname == "sam")
{
if (pass == "sam123")
returntrue;
}
returnfalse;
}
94 | P a g e
Response.Write("Invalid user name or password");
}
}
}
secondPage.aspx
secondPage.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="secondPage.aspx.cs"Inherits="secondPage"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</form>
</body>
</html>
secondPage.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclasssecondPage : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (Session["Username"] != null)
{
Label1.Text = Session["Username"].ToString();
}
}
}
Web.config
<?xmlversion="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
95 | P a g e
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<authenticationmode="Forms">
<formsloginUrl="secondPage.aspx"/>
</authentication>
<authorization>
<denyusers="?"/>
</authorization>
<compilationdebug="true"targetFramework="4.5.2" />
<httpRuntimetargetFramework="4.5.2" />
</system.web>
</configuration>
Output:
96 | P a g e
10.C.Create a web application to demonstrate use of various Ajax controls.
Code:
Design:
Default.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<%@RegisterAssembly="AjaxControlToolkit"namespace="AjaxControlToolkit"TagPrefix="ajaxToolkit"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
</div>
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<br/>
<asp:TextBoxID="TextBox1"runat="server"Columns="80"Rows="20"TextMode="MultiLine"></asp:TextBox>
<br/>
<br/>
<ajaxToolkit:HtmlEditorExtenderID="HtmlEditorExtender1"runat="server"TargetControlID="TextBox1"EnableSanitization="false">
<Toolbar>
<ajaxToolkit:Undo/><ajaxToolkit:Redo/>
<ajaxToolkit:Bold/><ajaxToolkit:Italic/>
<ajaxToolkit:Underline/><ajaxToolkit:StrikeThrough/>
<ajaxToolkit:Subscript/><ajaxToolkit:Superscript/>
<ajaxToolkit:JustifyLeft/><ajaxToolkit:JustifyCenter/>
<ajaxToolkit:JustifyRight/><ajaxToolkit:JustifyFull/>
<ajaxToolkit:InsertOrderedList/><ajaxToolkit:InsertUnorderedList/>
<ajaxToolkit:CreateLink/><ajaxToolkit:UnLink/>
<ajaxToolkit:RemoveFormat/><ajaxToolkit:SelectAll/>
97 | P a g e
<ajaxToolkit:UnSelect/><ajaxToolkit:Delete/>
<ajaxToolkit:Cut/><ajaxToolkit:Copy/>
<ajaxToolkit:Paste/><ajaxToolkit:BackgroundColorSelector/>
<ajaxToolkit:ForeColorSelector/><ajaxToolkit:FontNameSelector/>
<ajaxToolkit:FontSizeSelector/><ajaxToolkit:Indent/>
<ajaxToolkit:Outdent/><ajaxToolkit:InsertHorizontalRule/>
<ajaxToolkit:HorizontalSeparator/>
</Toolbar>
</ajaxToolkit:HtmlEditorExtender>
</form>
</body>
</html>
Output:
PRACTICAL 11
11. Programs to create and use DLL
S1:Select class library from the list and click Ok
S2:change the class name class1 to TS.
S3:Now to use the assembly ,create a new web site and then add TSClassLib.dll by add reference to Bin
folder.
S4:add new web page in website and design below page in .aspx file
Code:
11.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="11.aspx.cs"Inherits="_11"%>
<!DOCTYPEhtml>
98 | P a g e
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ButtonID="Button1"runat="server"Text="UpperCase"OnClick="Button1_Click"/>
<asp:ButtonID="Button2"runat="server"Text="LowerCase"OnClick="Button2_Click"/>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
11.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TSClassLib;
publicpartialclass_11 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
Output:
99 | P a g e
After click on LowerCase button:
100 | P a g e