Subject : Advance Web Programing 1) Aishwarya Waghmare (62) 2) Sandeep Singh (55) Subject Sir : Kiran more
Practical no 1: Working with basic C# and ASP .NET a. Create an application that obtains four int values from the user and displays the product. Default.aspx
Default.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
int r; r = Convert.ToInt32(TextBox1.Text) * Convert.ToInt32(TextBox2.Text) * Convert.ToInt32(TextBox3.Text) * Convert.ToInt32(TextBox4.Text); Label5.Text = "result" + r.ToString(); }
protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; Label1.Text = "";
} }
Default.aspx
Default.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
string s = TextBox1.Text; Label2.Text = "string length=" + s.Length; Label3.Text = "substring" + s.Substring(4, 3); Label4.Text = "upper string=" + s.ToUpper(); Label5.Text = "lower string=" + s.ToLower(); string rev = ""; for (int i = s.Length - 1; i >= 0; i--) { rev = rev + s[i]; } Label6.Text = "reverse string=" + rev.ToString(); Label7.Text = "replace s by t instring" + s.Replace('s', 't'); Label8.Text = "insert u in string:" + s.Insert(3, "u"); Label9.Text = "string truncate" + s.Trim(); Label10.Text = "remove string" + s.Remove(4); Label11.Text = "index of string:" + s.IndexOf('n');
}
protected void Button2_Click(object sender, EventArgs e) { Label2.Text = "";
Label3.Text = ""; Label4.Text = ""; Label5.Text = ""; Label6.Text = ""; Label7.Text = ""; Label8.Text = ""; Label9.Text = ""; Label10.Text = ""; Label11.Text = ""; TextBox1.Text = ""; } }
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. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace ConsoleApplication1 { class Program { public struct Student { public string StudID; public string StudName; public string CourseName; public string DOB; } static void Main(string[] args) { Student[] stud = new Student[2]; Console.WriteLine("Enter the Student details:"); for (int i = 0; i < 2; i++) { Console.WriteLine(); Console.WriteLine("Enter Student ID:"); stud[i].StudID = Console.ReadLine(); Console.WriteLine("Enter Student Name:");
stud[i].StudName = Console.ReadLine(); Console.WriteLine("Enter Student Course Name:"); stud[i].CourseName = Console.ReadLine(); Console.WriteLine("Enter Student DOB:"); stud[i].DOB = Console.ReadLine();
} Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Student details:"); for (int i = 0; i < 2; i++) { Console.WriteLine(); Console.WriteLine("Student ID:{0}", stud[i].StudID); Console.WriteLine("Student Name:{0}", stud[i].StudName); Console.WriteLine("Student Course Name:{0}", stud[i].CourseName); Console.WriteLine("Student DOB:{0}", stud[i].DOB); } Console.ReadKey(); } } }
2. Working with Object Oriented C# and ASP .NET a. Create simple application to perform following operations i. Finding factorial Value ii. Money Conversion iii. Quadratic Equation iv. Temperature Conversion i. Finding factorial Value Default.aspx
Default.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web;
using System.Web.UI; using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) { int a, b, c, i, n; a = 0; b = 1; Label7.Text = a.ToString() + b.ToString(); n = Convert.ToInt32(TextBox1.Text); for (i = 1; i <= n; i++) { c = a + b; Label7.Text = Label7.Text + c.ToString(); a = b; b = c; }
}
protected void Button2_Click(object sender, EventArgs e) { 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) { Label8.Text = "the given no is prime"; } else { Label8.Text = "the given no 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; } Label9.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; } Label10.Text = sum.ToString(); }
protected void Button5_Click(object sender, EventArgs e) { char c = Convert.ToChar(TextBox5.Text);
switch (c) { case 'a': Label11.Text = "a is vowel"; break; case 'e': Label11.Text = "a is vowel"; break; case 'i': Label11.Text = "a is vowel"; break; case 'o': Label11.Text = "a is vowel"; break; case 'u': Label11.Text = "a is vowel"; break; default: Label11.Text = "it is not vowel"; break;
} } }
2. Working with Object Oriented C# and ASP .NET a. Create simple application to perform following operations i. Finding factorial Value ii. Money Conversion iii. Quadratic Equation iv. Temperature Conversion using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e) { int i, number, fact;
number = Convert.ToInt32(TextBox1.Text); fact = number; for (i = number - 1; i >= 1; i--) { fact = fact * i; } Label2.Text = "factorial of a no is " + fact;
} }
ii money conversion Default.aspx
Default.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click1(object sender, EventArgs e) { curConv s = new curConv(); double r = Convert.ToDouble(TextBox1.Text); double rate = s.dolr(r); Label6.Text = rate.ToString(); } protected void Button2_Click(object sender, EventArgs e) { curConv s = new curConv(); double r = Convert.ToDouble(TextBox1.Text); double rate = s.Erous(r); Label7.Text = rate.ToString(); }
protected void Button3_Click(object sender, EventArgs e) { curConv s = new curConv(); double r = Convert.ToDouble(TextBox1.Text); double rate = s.pounds(r); Label8.Text = rate.ToString(); }
protected void Button4_Click(object sender, EventArgs e) {
curConv s = new curConv(); double r = Convert.ToDouble(TextBox1.Text); double rate = s.yen(r); Label9.Text = rate.ToString(); } } public class curConv { public double dolr(double r) { r = r * 0.015; return r; } public double Erous(double r) { r = r * 0.012; return r; } public double pounds(double r) { r = r * 0.0011; return r; } public double yen(double r) { r = r * 1.64;
return r; } }
Default.aspx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public class tempconv { public double ctof(double temp) { temp = 9 / 5 * temp + 32; return temp; } public double ftoc(double temp) { temp = (temp - 32) * 5 / 9; return temp; } }
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) { tempconv s = new tempconv(); double n = Convert.ToDouble(TextBox1.Text); double x = s.ctof(n); Label3.Text = x.ToString();
}
protected void Button2_Click(object sender, EventArgs e) { tempconv s = new tempconv(); double n = Convert.ToDouble(TextBox2.Text); double x = s.ftoc(n); Label4.Text = x.ToString(); } }
Default.aspx
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 { public int add(int a) { return a + a; } public int add(int a, int b) {
return a + b;
} public int add(int a, int b, int c) { return a + b + c;
} protected void Page_Load(object sender, EventArgs e) { int x, y, z; x = add(2); y = add(2, 3); z = add(2, 3, 4); Label1.Text = x.ToString(); Label2.Text = y.ToString(); Label3.Text = z.ToString(); }
}
singleinheritance.aspx
singleinheritance.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 single_inheritance : System.Web.UI.Page { 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); Label3.Text = x.ToString(); Label5.Text = y.ToString(); } } public class A { public int sqr(int val1) { return val1 * val1;
}
} public class B : A { public int cub(int val1) {
return
val1*val1*val1;
} }
multilevel.aspx
multilevel.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 multilevel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) { 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); Label5.Text = x.ToString();
Label6.Text = y.ToString(); Label7.Text = z.ToString(); } } public class A { public int pow2(int val1) { return val1 * val1;
} } public class B : A { public int pow3(int val1) {
return val1 * val1 * val1; } } public class C:B { public int pow4(int val1) { return val1 * val1 * val1 * val1;
} }
Hierarchical.aspx
Hierarchical.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 Hierarchical : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
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); Label3.Text = x.ToString(); Label4.Text = y.ToString(); } } 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; } }
iii)constructor overloading
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class consover : System.Web.UI.Page { 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); Label2.Text = obj1.r.ToString(); Label3.Text = obj2.r.ToString(); Label4.Text = obj3.r.ToString(); } } 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; } }
intfc.aspx
intfc.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public interface i1 { void show_i1(); } public interface i2 { void show_i2(); }
public partial class intfc : System.Web.UI.Page,i1,i2 { protected void Page_Load(object sender, EventArgs e) {
}
protected void btn1_Click(object sender, EventArgs e) { show_i1(); show_i2(); } public void show_i1() { lbl1.Text = "interface 1 called
" + txt1.Text; } public void show_i2() { lbl2.Text = "interface 2 called
" + txt1.Text; } }
Delegate demo_delegate.aspx
demo_delegate.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 Demo_delegate : System.Web.UI.Page { public delegate string dele(); public static string display1() { string s1 = "sandeep"; return s1; } public static string display2() { string s2 = "sandeep singh"; 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();
}
}
Practical 3(b).Demonstrate the use of Calendar control to perform following operations. a) Display messages in a calendar control b) Display vacation in a calendar control
c) Selected day in a calendar control using style d) Difference between two calendar dates 3.a).
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
} protected void btn_1_Click(object sender, EventArgs e) { Label11.Text = "Your first name is:" + txt_fn.Text; Label12.Text = "Your Last name is:" + txt_ln.Text; Label13.Text = "Your Address is:" + txt_add.Text; if (r_male.Checked) { Label14.Text = "Your gender is:" + r_male.Text; } else {
Label14.Text = "Your gender is:" + r_female.Text; } Label15.Text = "Your faviourate color is:" + dropdownlist1.SelectedItem; Label16.Text = "Your faviourate sub are:"; foreach (ListItem lst in chklst.Items) { if (lst.Selected == true) { Label16.Text += "
" + lst.Text; } Label16.Text += "
"; } } }
O/P:-
3.b).
Default.aspx.cs <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
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) { if (!IsPostBack) { Calendar1.Visible = true; } } protected void Button1_Click(object sender, EventArgs e) { Calendar1.Caption = "Calendar"; Label2.Text = "Today's Date = " + Calendar1.TodaysDate.ToString(); Label3.Text = "New year is at : 01-01-2019"; TimeSpan d = new DateTime(2019, 1, 1) - DateTime.Now; Label4.Text = "New year is after = " + d.Days.ToString() + "days";
} protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) { if (e.Day.Date.Day == 22 && e.Day.Date.Month == 9) { e.Cell.Controls.Add(new LiteralControl("
holiday")); } if (e.Day.Date >= new DateTime(2018, 9, 13) && e.Day.Date <= new DateTime(2018, 9, 18)) { e.Cell.BackColor = System.Drawing.Color.Green; e.Cell.BorderColor = System.Drawing.Color.White; } if (e.Day.IsOtherMonth) { e.Day.IsSelectable = false; e.Cell.BackColor = System.Drawing.Color.Green; } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Label1.Text = "Your selected date is = " + Calendar1.SelectedDate.ToShortDateString(); } protected void Button2_Click(object sender, EventArgs e) { Label1.Text = "";
Label2.Text = ""; Label3.Text = ""; Label4.Text = ""; Label5.Text = ""; Calendar1.SelectedDates.Clear(); } }
O/P:_
3.c
Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Default.aspx.cs using System; using System.Collections.Generic; using System.Data; 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) { if (!IsPostBack) { BindData(); } } protected void DataList1_SelectedIndexChanged(object sender, EventArgs e) {
} protected void BindData() { DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("XMLFile.xml")); if (ds != null && ds.HasChanges()) { DataList1.DataSource = ds; DataList1.DataBind(); } else { DataList1.DataBind(); } }
}
XMLFile.xml <studentdetail> <student> <sid>1 <sname>Sandeep <sclass>TYIT
<student> <sid>2 <sname>Mahesh <sclass>SYIT
<student> <sid>3 <sname>Sid <sclass>TYIT
o/p:-
4.a) Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
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) { this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None; }
protected void Button1_Click(object sender, EventArgs e) { if (this.IsValid) { ans.Text = "data saved"; ans.ForeColor = System.Drawing.Color.Green; } else { ans.Text = "data notsaved"; ans.ForeColor = System.Drawing.Color.Red;
} Label7.Text = "your First name is = " + fn_txt.Text + "
Your Last name is = " + ln_txt.Text; }
}
o/p:-
4.b
Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
XMLFile1.xml
~/pic/Google.jpg http://google.com
Please visit google 10 Support
~/pic/youtube.jpg http://youtube.com Please visit youtube 60 Youtube
o/p:-
4.c
WebUserControl.ascx <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
WebUserControl.ascx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class WebUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e) { Label2.Text = "Your name is = " + TextBox1.Text; } }
Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="uc1" TagName="WebUserControl" %>
o/p:-