Adin AWP PracticalManual
Adin AWP PracticalManual
Adin Dawood
Shaikh
Roll no: 345
TYIT
AWP Practical
Manual
1
Page
Practical 1 :Working with basic C# and ASP.NET
Practical 1a : Create an application that four int values from the user and displays the product
Design:
Practical1a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output:
2
--------------------------------------------------------------------------------
Page
Practical 1b : Create an application to demonstrate string operations.
Design:
Practical1b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
if (DropDownList1.SelectedItem.Text.Equals("Concate"))
{
result.Text = "Concatinate String : " + (str1 + str2);
}
elseif (DropDownList1.SelectedItem.Text.Equals("UpperCase"))
{
result.Text = "<br>" + "Upper case of String :" + "<br>" + (str1.ToUpper() + "" + str2.ToUpper());
}
elseif (DropDownList1.SelectedItem.Text.Equals("LowerCase"))
{
result.Text = "<br>" + "Lower case of String :" + "<br>" + (str1.ToLower() + "" + str2.ToLower());
}
elseif (DropDownList1.SelectedItem.Text.Equals("Length"))
{
result.Text = "<br>" + "Length of first string " + str1 + "<br>" + str1.Length;
}
elseif (DropDownList1.SelectedItem.Text.Equals("IsEmpty"))
{
if(String.IsNullOrEmpty(str1)&&String.IsNullOrEmpty(str2))
{
3
}
}
}
Output:
4
Page
--------------------------------------------------------------------------
Practical 1c : 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.
Design:
1c.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
5
Page
Output:
--------------------------------------------------------------------------
Design:
6
Page
1d.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
elseif (DropDownList1.SelectedItem.Text.Equals("Prime"))
{
int num1 = Convert.ToInt32(TextBox1.Text.ToString());
inti;
for (i = 2; i< num1 - 1; i++)
if (num1 % i == 0)
break;
if (i< num1 - 1)
{
result.Text = "IS NOT A PRIME NO";
else
{
result.Text = "A PRIME NUMBER";
}
elseif (DropDownList1.SelectedItem.Text.Equals("vowels"))
{
string str = TextBox1.Text.ToString().ToLower();
int c = 0;
for (inti = 0; i<str.Length; i++)
{
if ((str.Substring(i, 1)) == "a" || (str.Substring(i, 1)) == "e" || (str.Substring(i, 1)) == "i" ||
(str.Substring(i, 1)) == "o" || (str.Substring(i, 1)) == "u")
7
{
Page
c++;
}
}
elseif(DropDownList1.SelectedItem.Text.Equals("foreach loop"))
{
string s = TextBox1.Text.ToString();
foreach (char c in s)
{
Response.Write("<br>" + c);
}}}
Output: (a)
(b) (c)
8
Page
(d) (e)
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
9
Page
Practical 2 : Working with Object Oriented C# and ASP.NET
Practical 2a : Create simple application to perform following operation
i) Finding factorial Value
Design :
2ai.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicclassfacto
{
publicinti, f = 1, n;
publicfacto(intnum)
{
n = num;
for (i = 1; i<= n; i++)
{
f = f * i;
}
}
10
}
Page
Output:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2aii.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
TextBox4.Text = Convert.ToString(obj.r);
obj.rte();
}
Page
}
Conv.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclassConv
{
publicdouble d, r, e, a;
publicConv(double amount)
{
a = amount;
}
publicvoidrtd()
{
d = a / 69;
}
publicvoiddtr()
{
r = a * 69;
}
publicvoidrte()
{
e = a / 82.36;
}
publicvoidetr()
{
r = a * 82.36;
}
}
Output:
-------------------------------------------------------------------------------------------------------------------------------------------------------------
iii) Quadratic Equation.
Design:
12
Page
2iv.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
}
quadeqtn.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclassquadeqtn
{
publicdouble d, x1, x2;
publicstringmsg;
publicquadeqtn(int a, int b, int c)
{
d = b * b - 4 * a * c;
if (d == 0)
{
x1 = -b / (2.0 * a);
x2 = x1;
msg = "Both the roots are real and different <br> 1st Root is : " + x1 + "<br> 2nd Root is : " + x2 +
"<br>";
}
elseif (d > 0)
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
msg = "Both the roots are real and different <br> 1st Root is :" + x1 + "<br> 2nd Root is : " + x2 +
"<br>";
}
else
{
msg = "Root are imaginary, No solution.";
}
}
}
13
Page
Output:
--------------------------------------------------------------------------------------------------------------------------------------
2aiii.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Convobj = newConv(c);
obj.ctf();
Page
TextBox2.Text = obj.f.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
double c = Double.Parse(TextBox3.Text);
Convobj = newConv(c);
obj.ftc();
TextBox4.Text = obj.c.ToString();
}
}
Conv.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclassConv
{
publicdouble temp, f, c;
publicConv(double t)
{
temp = t;
}
publicvoidctf()
{
f = ((temp * 9 / 5)) + 32;
}
publicvoidftc()
{
c = ((temp - 32) * 5) / 9;
}
Output:
------------------------------------------------------------------------------------------------------------------------------------------------------------
15
Page
Practical 2b : Create simple application to demonstrate use of following concepts
i) Function Overloading
Design:
Default2bi.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Funcol.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
x = y = 0;
u = v = 0.0F;
Page
}
public void sum (int a, int b)
{
x = a + b;
}
public void sum (int a, int b, int c)
{
y = a + b + c;
}
public void sum (float a, float b)
{
u = a + b;
}
public void sum (float a,float b,float c)
{
v = a + b + c;
}
}
Output:
--------------------------------------------------------------------------------------------------------------------------------------
Practical2B1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
17
}
publicstringparentmethod()
{
string p = "This is base class method";
return p;
}
}
publicclassderived:basec
{
publicstringchildmethod()
{
string c = "This is derived class method";
return c;
}
}
Output:
-------------------------------------------------------------------------------------------------------------------------------------------------------------
b) MultiLevel Inheritance
18
Page
Design:
Practical2B2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
publicstringshow()
{
return ("First Base Class");
}
}
publicclassB :A
{
publicstringdisplay()
{
return ("Second base class and first derived class");
}
}
publicclassC :B
{
publicstringoutput()
{
return ("Second derived class");
}
}
Output:
19
Page
c) Multiple Inheritance
Design:
inheritance3.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partialclassinheritance3 :System.Web.UI.Page
{
protected voidPage_Load(objectsender,EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
rect r = newrect();
r.sides(Convert.ToInt16(TextBox1.Text), Convert.ToInt16(TextBox2.Text));
intaor = r.area();
TextBox3.Text = Convert.ToString(aor);
}
}
Mp.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
publicclasslengthofrect
{
publicintlen, brth;
publicvoidsides(int l, int b)
{
len = l;
brth = b;
}
}
publicinterfacecalc
{
intarea();
}
publicclassrect :lengthofrect , calc
{
publicintarea()
20
{
returnlen * brth;
Page
}
}
Output:
---------------------------------------------------------------------------------------------------------------------------------------------------------
d) Heirarchical Inheritance
Design:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Hci.cs
using System;
using System.Collections.Generic;
using System.Linq;
21
using System.Web;
publicclassP
{
Page
publicstringshowP()
{
string a = "Parent Class";
return a;
}
}
publicclassQ:P
{
publicstringshowQ()
{
string b = "Child1 Class";
return b;
}
}
publicclassR:P
{
publicstringshowR()
{
string c = "Child2 Class";
return c;
}
}
Output:
--------------------------------------------------------------------------------------------------------------------------------------
iii)Constructor Overloading
Design: 22
Page
Constructor Overloading.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
float t = m1 + m2 + m3;
return t;
Page
}
}
Output:
--------------------------------------------------------------------------------------------------------------------------------------
iv)Interfaces
Design:
Interfaces.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
Intrfc.cs
Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public interface calculation
{
float ans();
float input(float r);
}
public class Circle : calculation
{
public float rad, a;
public Circle()
{
rad = 0.0f;
}
public float input(float r)
{
rad = r;
return rad;
}
public float ans()
{
a = rad * rad * 3.14f;
return a;
}
}
Output:
--------------------------------------------------------------------------------------------------------------------------------------
2ci.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
{
Label1.Text="1st function called through Simple Delegate()method <br>";
Page
}
public void secondFunction()
{
Label2.Text="2nd function called through Simple Delegate()method <br>";
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SimpleDelegate sd1 = new SimpleDelegate(firstFunction);
sd1();
SimpleDelegate sd2 = new SimpleDelegate(secondFunction);
sd2();
}
}
Output: ---------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
b) Exception Handling
2c ii.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
class NegativeException : Exception
{
public NegativeException(string msg)
:base(msg)
{ }
}
public partial class _2cii : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (num < 0)
{
Page
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
27
Page
Practical 3 : Working with web controls
Practical 3a : Create a webpage with Various Server Controls to demonstrate Setting an use of their
Properties (eg:AutoPostBack)
Prac 3A.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
3b(i).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 _3b_i_ : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date == new DateTime(2022, 9, 7))
{
e.Cell.Controls.Add(new LiteralControl("<br/>AWP"));
}
if (e.Day.Date == new DateTime(2022, 9, 26))
{
e.Cell.Controls.Add(new LiteralControl("<br/>First Day of Navratri"));
}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
}
}
Output:
-------------------------------------------------------------------------------------------------------------------------------------------------------------
b) Display vacation in a calendar control
3b(ii).aspx.cs
using System;
29
using System.Collections.Generic;
using System.Linq;
Page
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
3b c).aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
30
}}
Output:
------------------------------------------------------------------------------------------------------------------------------------
3b d.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
3c a).aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
33
Page
Practical 4: Working with Form Controls
Practical 4a: Create a Registration Form to Demonstrate use of various Validation controls.
Prac4a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
--------------------------------------------------------------------------------------------------------------------------------------
34
Page
Practical 4c: Create Web Form to demonstrate use of User Controls
Design:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="uc" TagName="c" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:c ID ="WebUserControl" runat="server" />
</div>
</form>
</body>
</html>
WebUserControl.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
35
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
36
Page
Practical 6 : Working with Database
Practical 6a : Create a web application bind data in a multiline textbox by querying in another textbox.
Design:
6a.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;
6b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
------------------------------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPEhtml>
<scriptrunat="server">
}
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1">
<ItemTemplate>
id:
<asp:LabelID="idLabel"runat="server"Text='<%# Eval("id") %>'></asp:Label>
<br/>
name:
<asp:LabelID="nameLabel"runat="server"Text='<%# Eval("name") %>'></asp:Label>
<br/>
address:
<asp:LabelID="addressLabel"runat="server"Text='<%# Eval("address") %>'></asp:Label>
<br/>
<br/>
</ItemTemplate>
</asp:DataList>
<br/>
<br/>
<br/>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$
ConnectionStrings:mynewdatabaseConnectionString%>"SelectCommand="SELECT *FROM
Table_1"OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Output: 39
Page
Practical 7 : Working with Database
Practical 7a: Create a web application to display Databinding using dropdownlist control
7a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
40
------------------------------------------------------------------------------------------------------------------------------------
Page
Practical 7b: Create a web application for to display the phone no of an author using database
7b.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from author_details where id = " + TextBox1.Text +
" ", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
TextBox2.Text = Convert.ToString(dr["phone no"]);
}
}
}
Output:
----------------------------------------------------------------------------------------------------------------------------------------------------------
Practical 7c: Create a web application for inserting and deleting record from database (Using Execute-
Non Query)
Design:
41
Page
7c.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
--------------------------------------------------------------------------
-------------------------------------------------------------------------- 43
Page
Practical 8 : Working with Data Controls
Practical 8a : Create a Web Application to Demonstrate Various uses and properties of SqlDataSource
8a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
-------------------------------------------------------------------------------------------------------------------------------------
Practical 8b : Create a web application to demonstrate data binding using DetailsView and FormView
Control.
8b.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="8b.aspx.cs" Inherits="_8b" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
45
[Table_8b]"></asp:SqlDataSource>
<br />
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
</Fields>
</asp:DetailsView>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:mynewdatabaseConnectionString3 %>" SelectCommand="SELECT * FROM
[Table_8b]"></asp:SqlDataSource>
<br />
<br />
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource2">
<EditItemTemplate>
id:
<asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' />
<br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
id:
<asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' />
<br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
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='<%# Bind("id") %>' />
<br />
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>' />
<br />
address:
<asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
<br />
</ItemTemplate>
</asp:FormView>
46
</div>
Page
</form>
</body>
</html>
Output:
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
47
Page
Prac10_a
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
48
Page
Prac_11
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ClassLibrary1.Class1 c = new ClassLibrary1.Class1();
int sum = c.add(4, 5);
Console.WriteLine("addition is {0}", sum);
Console.ReadKey();
}
}
}
49
Page