Practical - 1: Object
Practical - 1: Object
Practical - 1: Object
Introduction -
In this tutorial we will introduce the new technology for building
websites. This new technology is known as ASP.Net. ASP.Net allows
the developer to build applications faster. This is achieved due to the
fast that ASP.Net makes use of the rich class libraries provided by
Microsoft. net framework.
Classic ASP -
Asp, which is now more commonly known as Classic Asp was used
extensively in 1990's. The idea of creating dynamic pages and linking
them with database was the main purpose of classic Asp. Asp used
html controls for user interaction. Apart from the good features
available in Asp programming, it also lacks in some of the major
areas. These areas include clean coding as asp pages were incline
pages and all the business logic as well as the interface was coded in
a single page. This produces many problem when the code had to be
updated or modified. Asp pages also lacked performance and
scalability which were fixed in ASP.Net. Let’s see what ASP.Net
technology has to offer a developer to build dynamic pages much
faster.
Use of Controls -
ASP.Net provides the developer with several controls to perform
basic as well as advanced operations. Controls provided in ASP.Net
falls under HTML Controls, HTML Server Controls and Web Server
Controls.
HTML Controls -
As you see HTML controls are very easy to use but they don't provide
much features. Microsoft decided to introduce HTML Server controls
which extends the functionality of simple HTML Controls.
2
<img src = "imagepath" runat="server">
As you can see that the image tag or control looks exactly like the
one that we have previously discussed. But it has an additional
attribute which is runat. The runat attribute denotes that this is a
HTML Server Control and will be executed on the Server rather than
the client.
Note: src attribute in the image tag denotes the path of the image it
can be "C:\MyDirectory\myImage.jpg"
Special Note -
When dealing with different types of controls one must always
remember that when to use which control. If the control will only act
as a static entity than you should always use HTML Controls. If the
control will be dynamic you should use Web Server Controls.
Language Options -
ASP.Net provides lets you choose the scripting language between
javascript and VbScript. This is beneficial for the java programmers as
3
well as the VB programmers since they already have the basic
background of the language.
Caching features -
ASP.Net also introduces caching features which increases the
performance of the application. Caching allows the developer to save
the recently used data in a cache variable so that if does not have to
spend any time looking for it in the future when anyone requests it.
Tools -
ASP.Net pages can be made in variety of tools. The most basic editor
is notepad or WordPad. To make the development faster Microsoft
has introduced Visual Studio development tool which lets the
developer build enterprise applications in less time. There are many
free tools available to build ASP.Net application one of them is
"WebMatrix" which can be downloaded from http://www.asp.net
4
PRACTICAL - 2
Object - Implement the validation concept in web form for
using ASP.Net control.
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Please Enter Name"
ForeColor="Blue" ControlToValidate="TextBox1"
ValidationGroup="a"></asp:RequiredFieldValidator><br />
<br />
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="Please Enter Password"
ForeColor="Blue" ControlToValidate="TextBox2"
ValidationGroup="a"></asp:RequiredFieldValidator><br />
<br />
<br />
6
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-
Size="XX-Large" ForeColor="Red"
ForeColor="Blue" ControlToValidate="TextBox3"
ValidationGroup="a"></asp:CompareValidator><br />
<br />
<br />
7
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ErrorMessage="Invailid Email"
ForeColor="Blue" ControlToValidate="TextBox4"
ValidationExpression="a"></asp:RegularExpressionValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="Please Enter Contect No"
ForeColor="Blue" ControlToValidate="TextBox5"
ValidationGroup="a"></asp:RequiredFieldValidator><br />
8
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-
Size="X-Large" ForeColor="Red"
<br /></div></form></body>
9
Output –
10
PRACTICAL - 3
Object - Implement the concept of boxing and unboxing.
Boxing -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Boxing
{
class Program
{
static void Main(string[] args)
{
int val = 50;
Console.ReadLine();
}
11
Output –
12
Unboxing -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace unboxing
{
class Program
{
static void Main(string[] args)
{
int val = 150;
int i = (int)obj;
Console.ReadLine();
}
13
Output –
14
PRACTICAL - 4
Object - Implement the concept of state management in web
form application(view, state, session state , application state).
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication32
{
public partial class _Default :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
15
Output -
16
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication34
{
public partial class _Default :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
17
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication34
{
public partial class bca :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
Label1.Text = Application
["user"].ToString();
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
18
namespace WebApplication34
{
public partial class _Default :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
19
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication34
{
public partial class bca :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
Label1.Text = session
["user"].ToString();
}
}
}
}
20
21
22
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<div>
23
Height="49px" Text="ANIL NAMAN SURESH NATHULAL"
Width="416px"></asp:Label></div>
</form>
</body>
</html>
24
25
PRACTICAL - 5
Object - Design a web form in asp.net using css.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<h1>hello</h1>
<div>
</div>
</form>
</body>
</html>
26
Output –
27
Stylesheet of css -
body
font-size:x-large;
color:inherit;
background-color:Blue;
font-style:italic;
font-variant:normal;
font-weight:normal;
text-transform:none;
h1
font-size:large;
font-weight:300;
border-color:Gray;
background-color:Green;
color:Orange;
text-decoration:underline;
28
PRACTICAL - 6
Object - Implement webform using database
connection(connected&disconnected).
namespace demotest
{
public partial class _Default : System.Web.UI.Page
{
string str,conn;
protected void Page_Load(object sender, EventArgs e)
{
conn="data source.\\sqlexpress;initial catalog=bca" integrated security=true;
}
protected void Button1_Click(object sender, EventArgs e)
{
sqlDataReader dr;
str="select * from student";
sqlconnection connobj=new sqlConnection(str,connobj);
connobj.open();
sqlcommand cmd=new sqlcommand(str,connobj);
dr=cmd.ExecuteReader();
GridView1.DataSource=dr;
GridView1.DataBind();
connobj.close();
}
}
29
Output -
30
31
PRACTICAL - 7
Object - Implement web form using grid view and also perform
edit update operation.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<div>
<Columns>
</Columns>
</asp:GridView>
32
</div>
</form>
</body>
</html>
33
Output –
34
PRACTICAL - 8
Object - Implement web forms perform insert operation
and display data and grid view.
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<head runat="server">
<title>Untitled Page</title>
</head>
<body bgcolor="#ffff00">
<div>
35
<asp:TextBox ID="TextBox1" runat="server" Height="30px"
Width="164px"></asp:TextBox>
<br />
<br />
<br />
<br />
36
<asp:Label ID="Label4" runat="server" BackColor="Red" Font-
Bold="True" Font-Size="X-Large"
<br />
ID="DropDownList1" runat="server">
<asp:ListItem>male</asp:ListItem>
<asp:ListItem>female</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
37
Height="40px" Text="Submit" Width="141px" />
</form>
</body>
</html>
38
Output –
39
PRACTICAL - 9
Object - Implement the concept of delegates in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Delegate
{
delegate void mydel();
class Program
{
Console.WriteLine("Ankit");
obj();
Console.ReadLine();
40
Output –
41
PRACTICAL - 10
Object - Implement the concept of Foreach loop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Loop
{
class Program
{
static void Main(string[] args)
foreach (int g in a)
{
Console.WriteLine("Element is
:"+ g);
Console.ReadLine();
} }
42
Output –
43