0% found this document useful (0 votes)
30 views86 pages

AWP Practical

Uploaded by

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

AWP Practical

Uploaded by

manasirs23hmit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 86

ADVANCED WEB PROGRAMMING GI09

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
int n1 = Convert.ToInt32(txt_n1.Text);
int n2 = Convert.ToInt32(txt_n2.Text);
int n3 = Convert.ToInt32(txt_n3.Text);
int n4 = Convert.ToInt32(txt_n4.Text);
int res;
res = n1 * n2 * n3 * n4;
lbl_res.Text="Multiplication is "+Convert.ToString(res);
}

protected void Button2_Click(object sender, EventArgs e)


{
txt_n1.Text = "";
txt_n2.Text = "";
txt_n3.Text = "";
txt_n4.Text = "";
lbl_res.Text = "";
ADVANCED WEB PROGRAMMING GI09

}
}

Output :
ADVANCED WEB PROGRAMMING GI09

b. Create an application to demonstrate string operations.


Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
string str = TextBox1.Text;
lbl_n1.Text = "String Length:" + str.Length;
lbl_n2.Text = "Substring:" + str.Substring(2, 4);
lbl_n3.Text = "upper string:" + str.ToUpper();
lbl_n4.Text = "lower string:" + str.ToLower();
string r="";
for(int i=str.Length-1;i>=0;i--)
{
r = r + str[i];
}
lbl_n5.Text = "Reverse string:" + r.ToString();
lbl_n6.Text = "Replace 's' by 't' in String: " + str.Replace('s', 't');
lbl_n7.Text = "Insert 'u' in String: " + str.Insert(3, "u");
lbl_n8.Text = "Remove String:" + str.Remove(4);
lbl_n9.Text = "Index of String:" + str.IndexOf('e');
lbl_n10.Text = "Index of String:" + str.IndexOf('e');
}

protected void Button2_Click(object sender, EventArgs e)


{
TextBox1.Text = "";
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

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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void Button2_Click(object sender, EventArgs e)


{
lbl_n1.Text = "";
lbl_n2.Text = "";
lbl_n3.Text = "";
lbl_n4.Text = "";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Calendar1.SelectedDates.Clear();

protected void Button1_Click(object sender, EventArgs e)


{
lbl_n5.Text = "Student Id :" + TextBox1.Text;
lbl_n6.Text = "Student Name :" + TextBox2.Text;
lbl_n7.Text = "Course Name :" + TextBox3.Text;
lbl_n8.Text = "Date Of Birth :" +
Calendar1.SelectedDate.ToShortDateString();
ADVANCED WEB PROGRAMMING GI09

}
}
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09

d. Create an application to demonstrate following operations.


1) Generate Fibonacci series.
2) Test for prime numbers.
3) Test for vowels.
4) Reverse a number.
5) Sum of digit of number.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

}
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

protected void Button5_Click(object sender, EventArgs e)


{
char c = Convert.ToChar(TextBox5.Text);
switch (c)
{
case 'a':
Label10.Text = "a is vowel";
break;
case 'e':
Label10.Text = "e is vowel";
break;
case 'i':
Label10.Text = "i is vowel";
break;
case 'o':
Label10.Text = "o is vowel";
break;
case 'u':
Label10.Text = "u is vowel";
break;
default:
Label10.Text = "It is not a vowel";
break;
}
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
int n1 = Convert.ToInt32(TextBox1.Text);
int a = 1;
for (int i = 1; i <= n1; i++)
{
a = i * a;
}
lbl_n2.Text = "Factorial is:" +a;

}
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;

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


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

protected void Button2_Click(object sender, EventArgs e)


{
double r = Convert.ToDouble(TextBox1.Text);
r = r * 0.012;
lbl_n3.Text = r.ToString();
}

protected void Button1_Click(object sender, EventArgs e)


{
double r = Convert.ToDouble(TextBox1.Text);
r = r * 0.015;
lbl_n2.Text = r.ToString();
}

protected void Button3_Click(object sender, EventArgs e)


{
double r = Convert.ToDouble(TextBox1.Text);
r = r * 0.011;
lbl_n4.Text = r.ToString();
}
ADVANCED WEB PROGRAMMING GI09

protected void Button4_Click(object sender, EventArgs e)


{
double r = Convert.ToDouble(TextBox1.Text);
r = r * 1.6;
lbl_n5.Text = r.ToString();
}
}

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
double T = Convert.ToDouble(TextBox1.Text);
T = ((9.0 / 5.0) * T) + 32;
lbl_n2.Text = T.ToString()+"F";
}

protected void Button2_Click(object sender, EventArgs e)


{
double T = Convert.ToDouble(TextBox2.Text);
T = (T - 32) * 5 / 9;
lbl_n4.Text = T.ToString()+"C";
}
}
Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09

b. Create simple application to demonstrate use of the following


concepts.
1) Function Overloading.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{ public int add1(int a)
{
return a+a;
}
public int add1(int a, int b)
{
return a + b;
}
public int add1(int a, int b, int c)
{
return a + b+ c;
}
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);
int c = Convert.ToInt32(TextBox3.Text);
int x, y, z;
x = add1(a);
y = add1(a,b);
z = add1(a,b,c);
lbl_n5.Text = x.ToString();
ADVANCED WEB PROGRAMMING GI09

lbl_n6.Text = y.ToString();
lbl_n7.Text = z.ToString();
}
}
Output :
ADVANCED WEB PROGRAMMING GI09

2) Inheritance (All Types)


a) Single Inheritance
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
public class A
{
public int sqr(int val1)
{
return val1 * val1;
}
}
public class B : A
{
public int cub(int val1)
{
int v1 = sqr(val1);
return v1 * val1;
}
}
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
B s = new B();
int n = Convert.ToInt32(TextBox1.Text);
int x = s.sqr(n);
int y = s.cub(n);
lbl_n4.Text = x.ToString();
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 partial class Pract_2b_Multiple_inheritance : System.Web.UI.Page


{
public class A
{
public int pow2(int val1)
{
return val1 * val1;
}

}
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;

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


{
public class A
{
public int a;
public int b;
}
public class B : A
{
public int add (int val1, int val2)
{
a = val1;
b = val2;
return a + b;
}
}
public class C : A
{
public int sub(int val1, int val2)
{
a = val1;
b = val2;
return a - b;
}
}
protected void Page_Load(object sender, EventArgs e)
{

}
ADVANCED WEB PROGRAMMING GI09

protected void Button1_Click(object sender, EventArgs e)


{
B s1 = new B();
C s2 = new C();
int m = Convert.ToInt32(TextBox1.Text);
int n = Convert.ToInt32(TextBox2.Text);
int x = s1.add(m,n);
int y = s2.sub(m, n);
Label4.Text = x.ToString();
Label6.Text = y.ToString();
}

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;

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


{
public class Add
{
public int r;
public Add(int a)
{
r = a + a;
}
public Add(int a, int b)
{
r = a + b;
}
public Add(int a, int b, int c)
{
r = a + b+ c;
}

}
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 :

c. Create simple application to demonstrate use of following concepts.


ADVANCED WEB PROGRAMMING GI09

1) Using delegates and events

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
public delegate string dele();
public static string display1()
{
string s1 = "SANIKA THALE";
return s1;
}
public static string display2()
{
string s2 = "MAYURI SURYAVANSHI";
return s2;
}
protected void Page_Load(object sender, EventArgs e)
{
dele d1 = new dele(display1);
d1();
dele d2 = new dele(display2);
d2();
Label1.Text = d1();
Label2.Text = d2();
}
}

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
try
{
int a = Convert.ToInt32(TextBox1.Text);
int[] b = { 12, 23, 33 };
int result;
result = (b[3] / a);
Label1.Text = "The result is:" + result.ToString();
}
catch(System.DivideByZeroException ex)
{
Label3.Text = ex.ToString();
}
catch(System.IndexOutOfRangeException ex)
{
Label3.Text = ex.ToString();
}

}
}

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;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string str = "BScIT";
if(ViewState["str"]==null)
{
ViewState["str"] = str;
}
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label2.Text = ViewState["str"].ToString();
if (RadioButton3.Checked == true)
{
RadioButton2.Checked = false;
RadioButton1.Checked = false;
}
else if (RadioButton1.Checked == true)
{
RadioButton2.Checked = false;
RadioButton3.Checked = false;
ADVANCED WEB PROGRAMMING GI09

}
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

b) Demonstrate the use of Calendar control to perform following


operations.
1) Display messages in a calendar control
2) Display vacation in a calendar control
3) Selected day in a calendar control using style
4) Difference between two calendar dates.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void Calendar1_DayRender(object sender,


DayRenderEventArgs e)
{
if (e.Day.Date.Day==5 && e.Day.Date.Month==9)
{
e.Cell.BackColor = System.Drawing.Color.Yellow;
Label lbl = new Label();
lbl.Text = "<br>Teachers Day!";
e.Cell.Controls.Add(lbl);

}
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);
}

protected void Button1_Click(object sender, EventArgs e)


{
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label1.Text = "Your Selected Date:" +
Calendar1.SelectedDate.Date.ToString();
Label2.Text = "Todays Date:" +
Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "Ganapti Vacation Starts: 9-25-2022";
TimeSpan d = new DateTime(2022, 9, 28) - DateTime.Now;
Label4.Text = "Days Remaining for Ganapti Vacation:" +
d.Days.ToString();
TimeSpan d1 = new DateTime(2022, 12, 31) - DateTime.Now;
Label5.Text = "Days Remaining for New Year:" + d1.Days.ToString();
}

protected void Button2_Click(object sender, EventArgs e)


{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}
}
ADVANCED WEB PROGRAMMING GI09

Pract 3b.aspx:
ADVANCED WEB PROGRAMMING GI09

Output:
ADVANCED WEB PROGRAMMING GI09

c)Demonstrate the use of Treeview control perform following


operations:
a) Treeview control and datalist
b) Treeview operations.

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;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("stdetail.xml"));
if (ds != null && ds.HasChanges())
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataBind();
}
}
}
ADVANCED WEB PROGRAMMING GI09

Output:
ADVANCED WEB PROGRAMMING GI09

Practical: 4
ADVANCED WEB PROGRAMMING GI09

4.Working with Form Controls.


a) Create a Registration form to demonstrate form to
demonstrate use of various Validation controls.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void CustomValidator1_ServerValidate(object source,


ServerValidateEventArgs args)
{
string str;
str = args.Value;
{
if (str.Length>3)
{
args.IsValid = true;
}
else
args.IsValid = false;
}
}
}
ADVANCED WEB PROGRAMMING GI09

Output :
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09

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

Code:

XML.File:

<?xml version="1.0" encoding="utf-8" ?>


<Advertisements>
<Ad>
<ImageUrl>2 terminal(2).png</ImageUrl>
<NavigateUrl>https://www.google.com</NavigateUrl>
<AlternateText>Linux RedHat Installtion</AlternateText>
<Impressions>20</Impressions>
<Keyword>Linux</Keyword>
</Ad>
<Ad>
<ImageUrl>3terminal.png</ImageUrl>
<NavigateUrl>https://www.google.com</NavigateUrl>
<AlternateText>Linux RedHat Installtion</AlternateText>
<Impressions>20</Impressions>
<Keyword>Linux</Keyword>
</Ad>
<Ad>
<ImageUrl>4terminal.png</ImageUrl>
<NavigateUrl>https://www.google.com</NavigateUrl>
<AlternateText>Linux RedHat Installtion</AlternateText>
<Impressions>20</Impressions>
<Keyword>Linux</Keyword>
</Ad>
<Ad>
<ImageUrl>5terminal.png</ImageUrl>
<NavigateUrl>https://www.google.com</NavigateUrl>
<AlternateText>Linux RedHat Installtion</AlternateText>
<Impressions>20</Impressions>
<Keyword>Linux</Keyword>
</Ad>
</Advertisements>
ADVANCED WEB PROGRAMMING GI09

Output:
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09
ADVANCED WEB PROGRAMMING GI09

C) Create Web Form to demonstrate use User Controls.

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>

<asp:Label ID="Label1" runat="server" Text="Welcome to


ASP.NET"></asp:Label>
<br />
<br />

</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:

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


5a.aspx.cs" Inherits="Pract_5a" %>

<!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:

<?xml version="1.0" encoding="utf-8" ?>


<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"
>
<siteMapNode url="pract2a.aspx" title="home" description="This is hme
page">
<siteMapNode url="pract2b.aspx" title="page2" description="This is
page 2" />
<siteMapNode url="pract2c.aspx" title="page3" description="This is
page 3" />
</siteMapNode>
</siteMap

Pract5a.aspx:

Output:
ADVANCED WEB PROGRAMMING GI09

b) Create a web application to demonstrate use of Master Page


with applying Styles and Themes for page beautification.
ADVANCED WEB PROGRAMMING GI09

Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
Label3.Text = "Sanika";
}
}

Master:
ADVANCED WEB PROGRAMMING GI09

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


CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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

C) Create a web application to demonstrate various State of


ASP.NET Pages.

1.View State
Code:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
String str = "Sanika Thale";
if(ViewState["nam"]==null)
{
ViewState["nam"] = str;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text=ViewState["nam"].ToString();
}
}
ADVANCED WEB PROGRAMMING GI09

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
Response.Redirect("WebForm3.aspx?User ID=" + TextBox1.Text +
"&UserName=" + TextBox2.Text);
}
}
WebForm2.aspx
ADVANCED WEB PROGRAMMING GI09

WebForm3.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Label3.Text = Request.QueryString["UserID"];
Label5.Text = Request.QueryString["Username"];
}
}
}

WebForm3.aspx

Output:
ADVANCED WEB PROGRAMMING GI09

3.Cookies
ADVANCED WEB PROGRAMMING GI09

Code:
WebForm4.aspx:

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


CodeFile="WebForm4.aspx.cs" Inherits="WebForm4" %>

<!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;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if(Request.Cookies["BackGroundColor"]!=null)
{
DropDownList1.SelectedValue =
Request.Cookies["BackGroundColor"].Value;
BodyTag.Style["BackGround-color"] = DropDownList1.SelectedValue;
}
}
protected void ColorSelector_IndexChanged(object sender, EventArgs e)
{

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;

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


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

}
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

6. b)Create a web application to display records by using


database.

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;

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


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

}
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

6.c) Demonstrate the use of DataList link control.

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text = "Name is :" + DropDownList1.SelectedValue.ToString();
}
}
ADVANCED WEB PROGRAMMING GI09

Output:
ADVANCED WEB PROGRAMMING GI09

7.b) Create a web application for to display the city name of


selected city using database.
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;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack==false)
{
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();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "city";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = " Your city is :" +
DropDownList1.SelectedValue.ToString();
}
}
ADVANCED WEB PROGRAMMING GI09

Output:
ADVANCED WEB PROGRAMMING GI09

7.c) Create a web application for inserting and deleting record


from a database. (Using Execute-Non Query).

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
string constr =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("insert into Student values
(@id,@name,@city,@mobile no.) )", con);

cmd.Parameters.AddWithValue("@id", TextBox1.Text);
cmd.Parameters.AddWithValue("@name", TextBox2.Text);

cmd.Parameters.AddWithValue("@city", TextBox3.Text);

cmd.Parameters.AddWithValue("@mobile no.", TextBox4.Text);


con.Open();
cmd.ExecuteNonQuery();
Label5.Text = "Record Inserted.";
con.Close();
ADVANCED WEB PROGRAMMING GI09

protected void Button2_Click(object sender, EventArgs e)


{
string constr =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("delete from Student where
name = @name", con);

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:

8.b) Create a web application to demonstrate data binding using


DetailsView and FormView Control.
ADVANCED WEB PROGRAMMING GI09

Pract8b.aspx

Output:
ADVANCED WEB PROGRAMMING GI09

8.c) Create a web application to display Using Disconnected Data


Access and DataBinding using GridView.

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;

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


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

protected void Button1_Click(object sender, EventArgs e)


{
string constr =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter ob = new SqlDataAdapter();
DataSet ds = new DataSet();
using (SqlConnection obc = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand("select * from Student", obc);
cmd.CommandType = CommandType.Text;
ob.SelectCommand = cmd;
ob.Fill(ds, "Student");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}

}
}
ADVANCED WEB PROGRAMMING GI09

Pract8c.aspx:

Output:

You might also like