Sie sind auf Seite 1von 43

PRACTICAL – 1

Object - Introduction to ASP.Net framework and C#.

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.

ASP.Net Web Applications -


ASP.Net is based on the .NET framework for building web
applications. Since ASP.Net is a part of the Microsoft. NET
1
Framework it has the ability to take advantage of rich class libraries
provided by Microsoft. The question is that why one should use
ASP.Net and not use classic asp or any other web programming
technology. Here are some of the features of ASP.Net that makes it
the best web application technology.

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 -

Html controls are the basic controls that are executed on


the client machine. These controls include textbox, label , image etc.
A simple example of html control can be given by the following code
which renders an image.
<img src="imagepath">

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.

HTML Server Controls -


HTML Server Controls looks exactly like the HTML Controls with one
difference that they are executed on the server rather than the
client. A simple example of HTML Server controls is given below:

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"

Web Server Controls -


Web Server Controls are the most advanced controls in ASP.Net.
Each control comes with tons of features that allows the developer
to complete the task in less time. Web Server Controls are executed
on the Server. Web Server Controls include datagrid control, datalist
control, calendar control and many many more.

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

ASP.Net Web Services -


Web Services has change the way we develop applications.
Sometimes its hard to grasp the idea behind the web service so I will
try to make it as simple as possible. A web service is not a whole
application, it’s a part or a component of a larger application. The
basic purpose of the web service is to create a link/bridge between
two different platforms and exchange data. This data is exchanged in
the form of XML. XML is nothing but text which is in structured form
that is why it's recognized by all platforms.

4
PRACTICAL - 2
Object - Implement the validation concept in web form for
using ASP.Net control.

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


CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Name" runat="server" Font-Bold="True" Font-


Size="XX-Large" ForeColor="Red"

Height="35px" Text="Name" Width="126px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp;

<asp:TextBox ID="TextBox1" runat="server"


Height="33px"></asp:TextBox>
5
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Please Enter Name"

ForeColor="Blue" ControlToValidate="TextBox1"
ValidationGroup="a"></asp:RequiredFieldValidator><br />

&nbsp;<br />

<br />

<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-


Size="XX-Large" ForeColor="Red"

Height="35px" Text="Password" Width="126px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp;

<asp:TextBox ID="TextBox2" runat="server"


Height="33px"></asp:TextBox>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

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

Height="35px" Text="Confirm Password"


Width="126px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp;

<asp:TextBox ID="TextBox3" runat="server"


Height="33px"></asp:TextBox>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

<asp:CompareValidator ID="CompareValidator1" runat="server"


ErrorMessage="Password Must Be Same"

ForeColor="Blue" ControlToValidate="TextBox3"
ValidationGroup="a"></asp:CompareValidator><br />

<br />

<br />

<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-


Size="XX-Large" ForeColor="Red"

Height="35px" Text="Email " Width="126px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp; &nbsp;

<asp:TextBox ID="TextBox4" runat="server"


Height="33px"></asp:TextBox>

7
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ErrorMessage="Invailid Email"

ForeColor="Blue" ControlToValidate="TextBox4"
ValidationExpression="a"></asp:RegularExpressionValidator><br />

<br /><br />

<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-


Size="XX-Large" ForeColor="Red"

Height="35px" Text="Contect Number" Width="126px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp; &nbsp;

<asp:TextBox ID="TextBox5" runat="server"


Height="33px"></asp:TextBox>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp;&nbsp;

<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="Please Enter Contect No"

ForeColor="Blue" ControlToValidate="TextBox5"
ValidationGroup="a"></asp:RequiredFieldValidator><br />

<br /><br /><br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

8
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-
Size="X-Large" ForeColor="Red"

Height="38px" Text="Submit" Width="89px" />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp;

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

object obj = val;

Console.WriteLine("(Ankit)Value is:" + val);

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;

object obj = val;

int i = (int)obj;

Console.WriteLine("(Ankit)Value is:" + i);

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)
{

protected void Button2_Click(object


sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
}
}
}
}

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)
{

protected void Button1_Click(object


sender, EventArgs e)
{
Application ["user"] =
TextBox1.Text;
Response.Redirect ("bca.aspx");
}
}
}

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)
{

protected void Button1_Click(object


sender, EventArgs e)
{
session ["user"] = TextBox1.Text;
Response.Redirect ("bca.aspx");
}
}
}

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" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

&nbsp;<asp:Label ID="Label1" runat="server" Font-Bold="True"


Font-Size="XX-Large"

ForeColor="Blue" Height="37px" Text="Name"


Width="132px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp;

<asp:TextBox ID="TextBox1" runat="server" Height="27px"


Width="156px"></asp:TextBox><br />

<br /> <br /> <br />

&nbsp;&nbsp;

<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-


Size="X-Large" ForeColor="Fuchsia"

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" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

anil naman nathulal suresh

<h1>hello</h1>

<form id="form1" runat="server">

<div>

</div>

</form>

</body>

</html>

26
Output –

27
Stylesheet of css -

body

font-family:'Times New Roman',Times,Sans-Serif;

font-size:x-large;

color:inherit;

background-color:Blue;

font-style:italic;

font-variant:normal;

font-weight:normal;

text-transform:none;

text-decoration:underline overline blink;

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

protected void Button2_Click(object sender, EventArgs e)


{
sqlDataAdapter ad;
str="select * from employee";
sqlconnection connobj=new sqlConnection(conn);
connobj.open();
sqlcommand cmd=new sqlcommand(str,connobj);
ad=new.sqlDataAdapter(cmd);
GridView1.DataSource=ds;
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" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

&nbsp;&nbsp;

<asp:GridView ID="GridView3" runat="server" DataSourceID="SqlDataSource1">

<Columns>

<asp:HyperLinkField Text="Edit" />

<asp:HyperLinkField Text="Delete" />

<asp:BoundField HeaderText="ID" />

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

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" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body bgcolor="#ffff00">

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" BackColor="Red" Font-


Bold="True" Font-Size="X-Large"

ForeColor="Black" Height="41px" Text="Name"


Width="176px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp;

35
<asp:TextBox ID="TextBox1" runat="server" Height="30px"
Width="164px"></asp:TextBox>

&nbsp; &nbsp;&nbsp;

<br />

<br />

<asp:Label ID="Label2" runat="server" BackColor="Red" Font-


Bold="True" Font-Size="X-Large"

ForeColor="Black" Height="41px" Text="Address"


Width="176px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp;&nbsp;

<asp:TextBox ID="TextBox2" runat="server" Height="30px"


Width="164px"></asp:TextBox><br />

<br />

<asp:Label ID="Label3" runat="server" BackColor="Red" Font-


Bold="True" Font-Size="X-Large"

ForeColor="Black" Height="41px" Text="phone"


Width="176px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp;

<asp:TextBox ID="TextBox3" runat="server" Height="30px"


Width="164px"></asp:TextBox><br />

<br />

36
<asp:Label ID="Label4" runat="server" BackColor="Red" Font-
Bold="True" Font-Size="X-Large"

ForeColor="Black" Height="41px" Text="E-MAIL ID"


Width="176px"></asp:Label>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp;&nbsp;

<asp:TextBox ID="TextBox4" runat="server" Height="30px"


Width="164px"></asp:TextBox><br />

&nbsp;&nbsp;<br />

&nbsp;<asp:Label ID="Label5" runat="server" BackColor="Red" Font-


Bold="True" Font-Size="X-Large"

ForeColor="Black" Height="44px" Text="Gender"


Width="170px"></asp:Label>&nbsp;<asp:DropDownList

ID="DropDownList1" runat="server">

<asp:ListItem>male</asp:ListItem>

<asp:ListItem>female</asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:DropDownList>

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />

<br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;


&nbsp; &nbsp;

<asp:Button ID="Button1" runat="server" BackColor="Snow" Font-


Bold="True" ForeColor="#404040"

37
Height="40px" Text="Submit" Width="141px" />

&nbsp; &nbsp; &nbsp; &nbsp;

<asp:Button ID="Button2" runat="server" BackColor="Snow" Font-


Bold="True" ForeColor="#404040"

Height="40px" Text="Display" Width="137px" /></div>

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

static void Ankit()

Console.WriteLine("Ankit");

static void Main(string[] args)

mydel obj = new mydel(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)

int[] a = { 10, 20, 30, 40, 50, 60,


70 };

foreach (int g in a)
{

Console.WriteLine("Element is
:"+ g);

Console.ReadLine();

} }

42
Output –

43

Das könnte Ihnen auch gefallen