AWP Practical
AWP Practical
Practical 1
1. Working with basic C# and ASP.NET
a. Create an application that obtains four int values from the
user and display the product.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
lbl_n1.Text = "";
lbl_n2.Text = "";
lbl_n3.Text = "";
lbl_n4.Text = "";
lbl_n5.Text = "";
lbl_n6.Text = "";
lbl_n7.Text = "";
lbl_n8.Text = "";
lbl_n9.Text = "";
lbl_n10.Text = "";
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
}
protected void Button1_Click(object sender, EventArgs e)
{
int a, b, c, i, n;
a = 0;
b = 1;
Label6.Text = a.ToString()+ b.ToString();
n = Convert.ToInt32(TextBox1.Text);
for (i = 1; i <= n; ++i)
{
c = a + b;
Label6.Text = Label1.Text + c.ToString();
a = b;
b = c;
}
}
protected void Button2_Click(object sender, EventArgs e)
ADVANCED WEB PROGRAMMING GI09
{
int i, c = 0, j, num;
num = Convert.ToInt32(TextBox2.Text);
for (j = 1; j <= num; j++)
{
i = num % j;
if (i == 0)
{
c = c + 1;
}
}
if (c == 2)
Label7.Text = "The given number is prime";
else
Label7.Text = "The given number is not prime";
}
protected void Button3_Click(object sender, EventArgs e)
{
long num, i, sum = 0;
num = Convert.ToInt32(TextBox3.Text);
while (num > 0)
{
i = num % 10;
sum = i + sum * 10;
num = num / 10;
}
Label8.Text = sum.ToString();
}
protected void Button4_Click(object sender, EventArgs e)
{
long num, i, sum = 0;
num = Convert.ToInt32(TextBox4.Text);
while (num > 0)
{
i = num % 10;
sum = i + sum;
num = num / 10;
}
Label9.Text = sum.ToString();
}
ADVANCED WEB PROGRAMMING GI09
Practical 2
2.Working with Object Oriented C# and ASP.NET
a. Create a simple application to perform following operations.
1)Finding Factorial Value
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
ADVANCED WEB PROGRAMMING GI09
Output :
ADVANCED WEB PROGRAMMING GI09
2) Money Conversion
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output :
ADVANCED WEB PROGRAMMING GI09
3) Temperature Conversion
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
lbl_n6.Text = y.ToString();
lbl_n7.Text = z.ToString();
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
lbl_n5.Text = y.ToString();
}
}
Output:
ADVANCED WEB PROGRAMMING GI09
b) Multilevel Inheritance
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
public class B : A
{
public int pow3(int val1)
{
int v1 = pow2(val1)
return v1 * val1;
}
}
public class C : B
{
public int pow4(int val1)
{
int v1 = pow3(val1);
return v1 * val1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
ADVANCED WEB PROGRAMMING GI09
{
C s = new C();
int n = Convert.ToInt32(TextBox1.Text);
int x = s.pow2(n);
int y = s.pow3(n);
int z = s.pow4(n);
lbl_n5.Text = x.ToString();
lbl_n6.Text = y.ToString();
lbl_n7.Text = z.ToString();
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
c) Hieraechical Inheritance
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
ADVANCED WEB PROGRAMMING GI09
Output :
3) Constructor Overloading
ADVANCED WEB PROGRAMMING GI09
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Page_Load(object sender, EventArgs e)
{
Add obj1 = new Add(2);
Add obj2 = new Add(2, 3);
Add obj3 = new Add(2, 3, 4);
Label7.Text = obj1.r.ToString();
Label8.Text = obj2.r.ToString();
Label9.Text = obj3.r.ToString();
}
}
ADVANCED WEB PROGRAMMING GI09
Output :
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output :
ADVANCED WEB PROGRAMMING GI09
2) Exception Handling
ADVANCED WEB PROGRAMMING GI09
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
Practical 3
3. Working with Web Forms and Controls.
a) Create a simple web page with various server controls to demonstrate
settings and use of their properties.(Example : AutoPostBack)
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
else
{
RadioButton3.Checked = false;
RadioButton1.Checked = false;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{
TextBox1.Text = TextBox1.Text + "" + ListBox1.Items[i] + "\n";
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
Label5.Text = DropDownList1.SelectedItem.Text;
}
protected void DropDownList2_SelectedIndexChanged(object sender,
EventArgs e)
{
Label6.Font.Size = int.Parse(DropDownList2.SelectedItem.Text);
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs
e)
{
Label7.BackColor = System.Drawing.Color.Red;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs
e)
{
Label7.BackColor = System.Drawing.Color.Green;
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs
e)
ADVANCED WEB PROGRAMMING GI09
{
Label7.BackColor = System.Drawing.Color.Blue;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Label7.Font.Bold = true;
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
Label7.Font.Italic = true;
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
Label7.Font.Underline = true;
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
if (e.Day.Date.Day==28 && e.Day.Date.Month == 9)
ADVANCED WEB PROGRAMMING GI09
{
Calendar1.SelectedDate = new DateTime(2022, 9, 23);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati Festival!";
e.Cell.Controls.Add(lbl1);
}
Pract 3b.aspx:
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
Code:
XMLFile.xml:
<?xml version="1.0" encoding="utf-8" ?>
<studentdetail>
<student>
<sid>1</sid>
<sname>Harshada</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>2</sid>
<sname>Vaidehi</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>3</sid>
<sname>Sita</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>4</sid>
<sname>Gita</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>
ADVANCED WEB PROGRAMMING GI09
Pract 3c.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output:
ADVANCED WEB PROGRAMMING GI09
Practical: 4
ADVANCED WEB PROGRAMMING GI09
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
Code:
XML.File:
Output:
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pract
4c.aspx.cs" Inherits="Pract_4c" %>
<%@ Register Src="~/Footer.ascx" TagName="footer" TagPrefix="stfooter"
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<stfooter:footer ID="footer1" runat="server" />
</form>
</body>
</html>
Footer.aspx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="Footer.ascx.cs" Inherits="Footer" %>
<table>
<tr>
<td align="center">Advanced Web Programming</td>
</tr>
</table>
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
Practical:5
5. Working with Navigation, Beautification and Master page.
a) Create a Web Form to demonstrate use of Website Navigation
controls and Site Map.
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<br />
<asp:Menu ID="Menu1" runat="server"
DataSourceID="SiteMapDataSource1">
</asp:Menu>
<br />
<br />
<br />
<br />
<br />
</div>
<br />
</form>
</body>
</html>
ADVANCED WEB PROGRAMMING GI09
Website.map:
Pract5a.aspx:
Output:
ADVANCED WEB PROGRAMMING GI09
Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Master:
ADVANCED WEB PROGRAMMING GI09
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<link href="demo_css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
CSS File:
body {
background-color:yellow;
font-family:Arial;
font-size:18px;
}
Skin File:
<asp:Label runat="server" ForeColor="red" />
<asp:Button runat="server" BorderStyle="Solid" BorderWidth="2px" />
Output:
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
1.View State
Code:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output:
2. Query String
ADVANCED WEB PROGRAMMING GI09
Code:
WebForm2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
WebForm3.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
WebForm3.aspx
Output:
ADVANCED WEB PROGRAMMING GI09
3.Cookies
ADVANCED WEB PROGRAMMING GI09
Code:
WebForm4.aspx:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="BodyTag" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server"
autopostback="true"
OnSelectedIndexChanged="ColorSelector_IndexChanged">
<asp:ListItem Value="White" Selected="True">Select
color...</asp:ListItem>
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp:DropDownList>
<br />
<br />
</div>
</form>
</body>
</html>
ADVANCED WEB PROGRAMMING GI09
WebForm4.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;
BodyTag.Style["BackGround-color"] = DropDownList1.SelectedValue;
HttpCookie cookie = new HttpCookie("BackGround-color");
cookie.Value = DropDownList1.SelectedValue;
cookie.Expires = DateTime.Now.AddMilliseconds(20);
Response.SetCookie(cookie);
}
}
Output:
ADVANCED WEB PROGRAMMING GI09
Practical:6
6.Working with Database
a) Create a web application bind data in multiline textbox by
querying in another textbox.
Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
}
protected void Button1_Click(object sender, EventArgs e)
{
string constr =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text,con);
SqlDataReader reader =cmd.ExecuteReader();
TextBox2.Text = "";
while(reader.Read())
{
TextBox2.Text += Environment.NewLine;
for(int i=0; i<reader.FieldCount-1; i++)
{
TextBox2.Text+=reader[i].ToString().PadLeft(15);
}
ADVANCED WEB PROGRAMMING GI09
}
reader.Close();
con.Close();
}
}
Web.config File:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<connectionStrings>
<add name="constr" connectionString="Data Source=(LocalDB)\
MSSQLLocalDB;AttachDbFilename='E:\AWP Practicals1\App_Data\
Student.mdf';Integrated Security=True"/>
</connectionStrings>
</configuration>
ADVANCED WEB PROGRAMMING GI09
Pract_6a.aspx
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
}
protected void Button1_Click(object sender, EventArgs e)
{
string constr =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("select name,city from
Student", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
Label1.Text = "";
while(reader.Read())
{
Label1.Text += reader["name"].ToString() + " " + "city :" +
reader["city"].ToString() + "<br>";
}
reader.Close();
con.Close();
}
}
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
DataList.aspx:
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
Practical :7
7.Working With Database
a) Create a web application to display Databinding using
DropdownList control.
Code:
Pract 7a.aspx.cs:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output:
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
Code:
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;
cmd.Parameters.AddWithValue("@id", TextBox1.Text);
cmd.Parameters.AddWithValue("@name", TextBox2.Text);
cmd.Parameters.AddWithValue("@city", TextBox3.Text);
cmd.Parameters.AddWithValue("@firstname", TextBox2.Text);
con.Open();
cmd.ExecuteNonQuery();
Label5.Text = "Record Deleted.";
con.Close();
}
}
Pract 7c.aspx :
ADVANCED WEB PROGRAMMING GI09
Output:
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
Practical:8
8.Working With data controls
8.a) Create a web application to demonstrate various uses and
properties of SqlDataSource.
Pract8a.aspx:
Output:
Pract8b.aspx
Output:
ADVANCED WEB PROGRAMMING GI09
Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
}
}
ADVANCED WEB PROGRAMMING GI09
Pract8c.aspx:
Output: