You are on page 1of 191

GOVERNMENT POLYTECHNIC, GANDHINAGAR

CERTIFICATE

This is to certify that Mr. / Ms. having


Enrollment No : has completed his/her practical
work for subject “Web Programming Using ASP.Net”, subject
code “3351603” during his/her 5th Semester satisfactorily in
his/her term ending at Date 14/11/2014 for the year 2014.

/ / Darshak B. Mehta

DATE OF SUBMISSION: SIGNATURE OF FACULTY


Page #: 1 | Government Polytechnic, Gandhinagar

PRACTICAL: 1
AIM: Getting acquainted with Visual Studio environment. (Create new
web project, open existing web project, building website, and study of
toolbars, menu etc.)

This walkthrough provides you with an introduction to Microsoft Visual Web Developer. It
guides you through creating a simple page by using Visual Web Developer, illustrating the basic
techniques of creating a new page, adding controls, and writing code.

Tasks illustrated in this walkthrough include:

 Creating a file system Web site.


 Familiarizing yourself with Visual Web Developer.
 Creating a single-file ASP.NET page in Visual Web Developer.
 Adding controls.
 Adding event handlers.
 Running pages with the Web Servers in Visual Web Developer.

 The .NET Framework

Creating a Web Site and Page

In this part of the walkthrough, you will create a Web site and add a new page to it. You will also
add HTML text and run the page in your Web browser.

For this walkthrough, you will create a file system Web site that does not require that you work
with Microsoft Internet Information Services (IIS). Instead, you will create and run your page in
the local file system.

A file system Web site is one that stores pages and other files in a folder that you choose
somewhere on your local computer. Other Web site options include a local IIS Web site, which
stores your files in a subfolder of the local IIS root (typically, \Inetpub\Wwwroot\). An FTP site
stores files on a remote server that you gain access to across the Internet by using File Transfer
Protocol (FTP). A remote site stores files on a remote server that you can access across a local
network. For more information, see Walkthrough: Editing Web Sites with FTP in Visual Web
Developer. Also, Web site files can be stored in a source control system such as Visual
SourceSafe. For more information, see Introducing Source Control.

To create a file system Web site

1. Open Visual Web Developer.


2. On the File menu, click New Web Site.

The New Web Site dialog box appears, as shown in the following screen shot.

Web Programming using ASP.Net Practicals


New Web Site dialog box

3. Under Visual Studio installed templates, click ASP.NET Web Site.

When you create a Web site, you specify a template. Each template creates a Web
application that contains different files and folders. In this walkthrough, you are creating
a Web site based on the ASP.NET Web Site template, which creates some folders and a
few default files.

4. In the Location box, select the File System box, and then enter the name of the folder
where you want to keep the pages of your Web site.

For example, type the folder name C:\BasicWebSite.

5. In the Language list, select Visual Basic or Visual C#.

The programming language you choose will be the default for your Web site. However,
you can use multiple languages in the same Web application by creating pages and
components in different programming languages.

6. Click OK.

Visual Web Developer creates the folder and a new page named Default.aspx. When a
new page is created, by default Visual Web Developer displays the page in Source view,
where you can see the page's HTML elements. The following screen shot shows the
Source view of a default Web page.

Source view of default page

A Tour of Visual Web Developer

Before you proceed with working on the page, it is useful to familiarize yourself with the Visual
Web Developer development environment. The following illustration shows you the windows
and tools that are available in Visual Web Developer.

This diagram shows default windows and window locations. The View menu allows you to
display additional windows, and to rearrange and resize windows to suit your preferences. If
changes have already been made to the window arrangement, what you see will not match the
diagram.
Diagram of Visual Web Developer environment
To familiarize yourself with the Web designer in Visual Web Developer

 Examine the preceding illustration and match the text to the following list, which
describes the most commonly used windows and tools. (Not all windows and tools that
you see are listed here, only those marked in the preceding illustration.)
o Toolbars. Provide commands for formatting text, finding text, and so on. Some
toolbars are available only when you are working in Design view.
o Solution Explorer. Displays the files and folders in your Web site.
o Document window. Displays the documents you are working on in tabbed
windows. You can switch between documents by clicking tabs.
o Properties window. Allows you to change settings for the page, HTML elements,
controls, and other objects.
o View tabs. Present you with different views of the same document. Design view
is a near-WYSIWYG editing surface. Source view is the HTML editor for the
page. Split view displays both the Design view and the Source view for the
document. You will work with the Design and Source views later in this
walkthrough. If you prefer to open Web pages in Design view, on the Tools
menu, click Options, select the HTML Designer node, and change the Start Pages
In option.
o Toolbox. Provides controls and HTML elements that you can drag onto your
page. Toolbox elements are grouped by common function.
o Server Explorer/Database Explorer. Displays database connections. If Server
Explorer is not visible in Visual Web Developer, on the View menu, click Server
Explorer or Database Explorer.

Creating a New Web Forms Page

When you create a new Web site, Visual Web Developer adds an ASP.NET page (Web Forms
page) named Default.aspx. You can use the Default.aspx page as the home page for your Web
site. However, for this walkthrough, you will create and work with a new page.
To add a page to the Web site

1. Close the Default.aspx page. To do this, right-click the tab containing the file name and
select Close.
2. In Solution Explorer, right-click the Web site (for example, C:\BasicWebSite), and then
click Add New Item.
3. Under Visual Studio installed templates, click Web Form. The following screen shot
shows the Add New Item dialog box.

Add New Item dialog box

4. In the Name box, type FirstWebPage.


5. In the Language list, choose the programming language you prefer to use (Visual Basic,
C#, or J#). When you created the Web site, you specified a default language. However,
each time you create a new page or component for your Web site, you can change the
language from the default. You can use different programming languages in the same
Web site.
6. Clear the Place code in separate file check box.

In this walkthrough, you are creating a single-file page with the code and HTML in the
same page. The code for ASP.NET pages can be located either in the page or in a
separate class file. To learn more about keeping the code in a separate file, see
Walkthrough: Creating a Basic Web Page with Code Separation in Visual Web
Developer.

7. Click Add.

Visual Web Developer creates the new page and opens it.

Adding HTML to the Page

In this part of the walkthrough, you will add some static text to the page.

To add text to the page

1. At the bottom of the document window, click the Design tab to switch to Design view.

Design view displays the page that you are working on in a WYSIWYG-like way. At this
point, you do not have any text or controls on the page, so the page is blank except for a
dashed line that outlines a rectangle. This rectangle represents a div element on the page.

2. Click inside the rectangle that is outlined by a dashed line.


3. Type Welcome to Visual Web Developer and press Enter twice.

The following screen shot shows the text you typed in Design view.

Welcome text as seen in Design view

4. Switch to Source view.


You can see the HTML that you created by typing in Design view, as shown in the
following screen shot.

Welcome text as seen in Source view

Running the Page

Before you proceed with adding controls to the page, you can try running it. To run a page, you
need a Web server. In a production Web site, you use IIS as your Web server. However, to test a
page, you can use the ASP.NET Development Server, which runs locally and does not require
IIS. For file system Web sites, the default Web server in Visual Web Developer is the ASP.NET
Development Server.

To run the page

1. In Solution Explorer, right-click FirstPage.aspx and select Set as Start Page.


2. Press CTRL+F5 to run the page.
Visual Web Developer starts the ASP.NET Development Server. An icon appears on the
toolbar to indicate that the Visual Web Developer Web server is running, as shown in the
following screen shot.

Visual Web Developer Web server icon

The page is displayed in the browser. Although the page you created has an extension of
.aspx, it currently runs like any HTML page.

To display a page in the browser you can also right-click the page in Solution Explorer
and select View in Browser.

If the browser displays a 502 error or an error indicating that the page cannot be
displayed, you might need to configure your browser to bypass proxy servers for local
requests. For details, see How to: Bypass a Proxy Server for Local Web Requests.

3. Close the browser.

Adding and Programming Controls

In this part of the walkthrough, you will add a Button, a TextBox, and a Label control to the page
and write code to handle the Click event for the Button control.

You will now add server controls to the page. Server controls, which include buttons, labels, text
boxes, and other familiar controls, provide typical form-processing capabilities for your
ASP.NET Web pages. However, you can program the controls with code that runs on the server,
not the client.

To add controls to the page

1. Click the Design tab to switch to Design view.


2. Put the insertion point at the end of the Welcome to Visual Web Developer text and press
ENTER five or more times to make some room in the div element box.
3. In the Toolbox, expand the Standard group.
4. Drag a TextBox control onto the page and position it in the middle of the div element box
that has Welcome to Visual Web Developer in the first line.
5. Drag a Button control onto the page and position it to the right of the TextBox control.
6. Drag a Label control onto the page and position it on a separate line below the Button
control.
7. Put the insertion point above the TextBox control, and then type Enter your name:.

This static HTML text is the caption for the TextBox control. You can mix static HTML
and server controls on the same page. The following screen shot shows how the three
controls appear in Design view.
Controls in Design View

Setting Control Properties

Visual Web Developer offers you various ways to set the properties of controls on the page. In
this part of the walkthrough, you will set properties in both Design view and Source view.

To set control properties

1. Select the Button control, and then in the Properties window, set Text to Display Name,
as shown in the following screen shot.

Changed Button control text

2. Switch to Source view.

Source view displays the HTML for the page, including the elements that Visual Web
Developer has created for the server controls. Controls are declared using HTML-like
syntax, except that the tags use the prefix asp: and include the attribute runat="server".
Page #: 10 | Government Polytechnic, Gandhinagar

Control properties are declared as attributes. For example, when you set the Text property
for the Button control, in step 1, you were actually setting the Text attribute in the
control's markup.

Note that all the controls are inside a <form> element, which also has the attribute
runat="server". The runat="server" attribute and the asp: prefix for control tags mark the
controls so that they are processed by ASP.NET on the server when the page runs. Code
outside of <form runat="server"> and <script runat="server"> elements is sent
unchanged to the browser, which is why the ASP.NET code must be inside an element
whose opening tag contains the runat="server" attribute.

3. Put the insertion point after asp:Label in the <asp:Label> tag, and then press
SPACEBAR.

A drop-down list appears that displays the list of properties you can set for a Label
control. This feature, referred to as IntelliSense, helps you in Source view with the syntax
of server controls, HTML elements, and other items on the page. The following screen
shot shows the IntelliSense drop-down list for the Label control.

IntelliSense for Label control

Web Programming using ASP.Net Practicals


4. Select ForeColor and then type an equal sign and a quotation mark (="). IntelliSense
displays a list of colors.

Note:

You can display an IntelliSense drop-down list at any time by pressing CTRL+J.

5. Select a color for the Label control's text. Make sure you select a color that is dark
enough to read against a white background.

The ForeColor attribute is completed with the color that you have selected, including the
closing quotation mark.

Programming the Button Control

For this walkthrough, you will write code that reads the name that the user enters into the text
box and then displays the name in the Label control.

To add a default button event handler

1. Switch to Design view.


2. Double-click the Button control.

Visual Web Developer switches to Source view and creates a skeleton event handler for
the Button control's default event, the Click event.

Note:

Double-clicking a control in Design view is just one of several ways you can create event
handlers.

3. Inside the handler, type the following:

Label1.

When you type the period after Label, Visual Web Developer displays a list of available
members for the Label control, as shown in the following screen shot.

Available Label control members


4. Finish the Click event handler for the button so that it reads as shown in the following
code example.

VB

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs)
Label1.Text = Textbox1.Text & ", welcome to Visual Web Developer!"
End Sub

C#

protected void Button1_Click(object sender, System.EventArgs e)


{
Label1.Text = TextBox1.Text + ", welcome to Visual Web Developer!";
}

5. Scroll down to the <asp:Button> element. Note that the <asp:Button> element now has
the attribute OnClick="Button1_Click". This attribute binds the button's Click event to
the handler method you coded in step 4.
Event handler methods can have any name; the name you see is the default name created
by Visual Web Developer. The important point is that the name used for the OnClick
attribute must match the name of a method in the page.

If you are using Visual Basic with code separation, Visual Web Developer does not add
an explicit OnClick attribute. Instead, the event is bound to the handler method using a
Handles keyword on the handler declaration itself.

Running the Page

You can now test the server controls on the page.

To run the page

1. Press CTRL+F5 to run the page in the browser.

The page again runs using the ASP.NET Development Server.

2. Enter a name into the text box and click the button.

The name you entered is displayed in the Label control. Note that when you click the
button, the page is posted to the Web server. ASP.NET then recreates the page, runs your
code (in this case, the Button control's Click event handler runs), and then sends the new
page to the browser. If you watch the status bar in the browser, you can see that the page
is making a round trip to the Web server each time you click the button.

3. In the browser, view the source of the page you are running.

In the page source code, you see only ordinary HTML; you do not see the <asp:>
elements that you were working with in Source view. When the page runs, ASP.NET
processes the server controls and renders HTML elements to the page that perform the
functions that represent the control. For example, the <asp:Button> control is rendered as
the HTML element <input type="submit">.

4. Close the browser.

Working with Additional Controls

In this part of the walkthrough, you will work with the Calendar control, which displays dates a
month at a time. The Calendar control is a more complex control than the button, text box, and
label you have been working with and illustrates some further capabilities of server controls.

In this section, you will add a Calendar control to the page and format it.
To add a Calendar control

1. In Visual Web Developer, switch to Design view.


2. From the Standard section of the Toolbox, drag a Calendar control onto the page and
position it below the div element that contains the other controls:

The calendar's smart tag panel is displayed. The panel displays commands that make it
easy for you to perform the most common tasks for the selected control. The following
screen shot shows the Calendar control as rendered in Design view.

Calendar control in Design view

3. In the smart tag panel, choose Auto Format.

The Auto Format dialog box is displayed, which allows you to select a formatting scheme
for the calendar. The following screen shot shows the Auto Format dialog box for the
Calendar control.

Auto Format dialog box for the Calendar control


4. From the Select a scheme list, select Simple and then click OK.
5. Switch to Source view.

You can see the <asp:Calendar> element. This element is much longer than the elements
for the simple controls you created earlier. It also includes subelements, such as
<WeekEndDayStyle>, which represent various formatting settings. The following screen
shot shows the Calendar control in Source view.

Calendar control in Source view


Programming the Calendar Control

In this section, you will program the Calendar control to display the currently selected date.

To program the Calendar control

1. In Design view, double-click the Calendar control.

A new event handler is created in Source view.

2. Finish the SelectionChanged event handler with the following highlighted code.

VB

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal


e As System.EventArgs)
Label1.Text = Calendar1.SelectedDate.ToLongDateString()
End Sub

C#
protected void Calendar1_SelectionChanged(object sender,
System.EventArgs e)
{
Label1.Text = Calendar1.SelectedDate.ToLongDateString();
}

Running the Page

You can now test the calendar.

To run the page

1. Press CTRL+F5 to run the page in the browser.


2. Click a date in the calendar.

The date you clicked is displayed in the Label control.

3. In the browser, view the source code for the page.

Note that the Calendar control has been rendered to the page as a table, with each day as
a <td> element containing an <a> element.

4. Close the browser.

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 2
AIM : Develop simple application using .net facility

Practical2.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Practical2.aspx.vb"
Inherits="Practical3.Practical2" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Logo</td>
<td>
<asp:Image ID="Image1" runat="server" Height="100px"
ImageUrl="~/Chrysanthemum.jpg" Width="100px" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Date of Birth</td>
<td>
<asp:Button ID="btnSubmit0" runat="server" Text="..." />
<asp:Calendar ID="Calendar1" runat="server"
Visible="False"></asp:Calendar>
<asp:Label ID="lblDate" runat="server"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:HyperLink ID="lnkGoogle" runat="server"
NavigateUrl="http://www.google.com">Google</asp:HyperLink>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Practical2.aspx.vb
Public Class Practical2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnSubmit0_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnSubmit0.Click
Calendar1.Visible = True
End Sub

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As


EventArgs) Handles Calendar1.SelectionChanged
lblDate.Text = Calendar1.SelectedDate.ToString.Split(" ")(0)
Calendar1.Visible = False
End Sub
End Class
SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 3
AIM: Develop simple web page using built in Objects.

BuiltInObjectsDemo.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="BuiltInObjectsDemo.aspx.vb"
Inherits="Practical2.BuiltInObjectsDemo" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

BuiltInObjectsDemo.aspx.vb
Public Class BuiltInObjectsDemo
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

Response.Write("<br />Server Mappath : " & Server.MapPath("\"))


Response.Write("<br />Server Machine Name : " & Server.MachineName)
Response.Write("<br />Server Script Time Out : " & Server.ScriptTimeout)
Response.Write("<br />Trace Enabled? : " & Trace.IsEnabled)
Response.Write("<br />Trace Mode : " & Trace.TraceMode)
Response.Write("<br />Client Certificate : " &
Request.ClientCertificate.ToString)
Response.Write("<br />Request HTTP Method : " & Request.HttpMethod)

End Sub

End Class
SCREENSHOTS:

Start Date End/Sign Date Faculty Sign Remarks/Grade


Page #: 24 | Government Polytechnic, Gandhinagar

PRACTICAL: 4
AIM : Design a web form to allow user to enter following details in
his Resume using Web Server Controls. Set validations using
properties. When data is submitted it must be viewed in the panel
below the form. Fields of Resume are

FirstName, Surname, Gender, Address, City, Pincode, Phone,


Qualification (Diploma, Bachelor, Master), Specialization subject,
Percentage.

Register.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Register.aspx.vb"
Inherits="A1BatchPract4.Register" %>

<!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></title>
<style type="text/css">
.style1
{
height: 26px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table style="width:100%;">
<tr>
<td>
First Name</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"
MaxLength="20"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Last Name</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"
MaxLength="20"></asp:TextBox>
</td>
<td>

Web Programming using ASP.Net Practicals


&nbsp;</td>
</tr>
<tr>
<td>
Gender</td>
<td>
<asp:RadioButton ID="rdoMale" runat="server" GroupName="gender"
Text="Male" Checked="True" />
<asp:RadioButton ID="rdoFemale" runat="server" GroupName="gender"
Text="Female" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Address</td>
<td>
<asp:TextBox ID="txtAddress" runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td class="style1">
City</td>
<td class="style1">
<asp:DropDownList ID="drpCity" runat="server">
<asp:ListItem>Ahmedabad</asp:ListItem>
<asp:ListItem>Gandhinagar</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</td>
<td class="style1">
</td>
</tr>
<tr>
<td>
Pincode</td>
<td>
<asp:TextBox ID="txtPinCode" runat="server" MaxLength="6"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Phone</td>
<td>
<asp:TextBox ID="txtPhone" runat="server" MaxLength="11"
TextMode="SingleLine" ></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
Page #: 26 | Government Polytechnic, Gandhinagar

Qualification</td>
<td>
<asp:TextBox ID="txtQualification" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Specialization Subject</td>
<td>
<asp:TextBox ID="txtSpecialization" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Percentage</td>
<td>
<asp:TextBox ID="txtPercentage" runat="server"
MaxLength="3"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnSubmit" runat="server" style="margin-bottom: 0px"
Text="Submit Resume Data" />
</td>
<td>
<input id="Reset1" type="reset" value="ReSeT" /></td>
</tr>
</table>
<asp:Panel ID="Panel1" runat="server" Visible="False">
<table style="width:100%;">
<tr>
<td>
First Name</td>
<td>
<asp:Label ID="lblFirstName" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Last Name</td>
<td>
<asp:Label ID="lblLastName" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>

Web Programming using ASP.Net Practicals


<td>
Gender</td>
<td>
<asp:Label ID="lblGender" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Address</td>
<td>
<asp:Label ID="lblAddress" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
City</td>
<td>
<asp:Label ID="lblCity" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Pincode</td>
<td>
<asp:Label ID="lblPinCode" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Phone</td>
<td>
<asp:Label ID="lblPhone" runat="server" Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Qualification</td>
<td>
<asp:Label ID="lblQualification" runat="server"
Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Specialization Subject</td>
<td>
<asp:Label ID="lblSpecilization" runat="server"
Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Percentage</td>
<td>
<asp:Label ID="lblPercentage" runat="server"
Text="Label"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
</html>

Register.aspx.vb
Public Class Register
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnSubmit.Click
lblFirstName.Text = txtFirstName.Text
lblLastName.Text = txtLastName.Text
If rdoMale.Checked = True Then
lblGender.Text = "Male"
Else
lblGender.Text = "Female"
End If
lblAddress.Text = txtAddress.Text
lblPhone.Text = txtPhone.Text
lblPinCode.Text = txtPinCode.Text
lblQualification.Text = txtQualification.Text
lblSpecilization.Text = txtSpecialization.Text
lblCity.Text = drpCity.Text
lblPercentage.Text = txtPercentage.Text

Panel1.Visible = True
End Sub
End Class
SCREENSHOTS:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 5
AIM : Create a web form where user enters following marks.
ASP.NET, JAVA, ISS, Project (All out of 100). When user submits the
marks, numeric value validation must be done. On entering marks,
the grade should be displayed in message box .
% > 90 and <<=100 AA
> 80 and <<=90 AB
> 70 and <<=80 BB
> 60 and <<=67 BC
>50 and <<=60 CC
>40 and <= 50 DD
Else Fail

Practical 5.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="practical 5.aspx.vb"
Inherits="Practical5.practical_5" %>

<!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></title>
<style type="text/css">
.style1
{
width: 156px;
}
.style2
{
width: 211px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td bgcolor="Silver" class="style2"
style="font-family: Arial, Helvetica, sans-serif; font-size: large;
font-weight: bold; font-style: inherit; font-variant: inherit; text-transform: inherit;
color: #0000FF;">
ASP.NET</td>
<td class="style1">
<asp:TextBox ID="txtasp" runat="server" BackColor="White"
BorderColor="#FF3300"
BorderStyle="Ridge" Font-Bold="False" Font-
Overline="False"></asp:TextBox>
</td>
<td>
<asp:Label ID="lblasp" runat="server" Text="Label"
ViewStateMode="Disabled"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="Silver" class="style2"
style="font-family: Arial, Helvetica, sans-serif; font-size: large;
font-weight: bold; font-style: inherit; font-variant: inherit; text-transform: inherit;
color: #0000FF;">
JAVA</td>
<td class="style1">
<asp:TextBox ID="txtjava" runat="server" BackColor="White"
BorderColor="#FF3300" BorderStyle="Ridge" Font-Bold="False"
Font-Overline="False"></asp:TextBox>
</td>
<td>
<asp:Label ID="lbljava" runat="server" Text="Label"
ViewStateMode="Disabled"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="Silver" class="style2"
style="font-family: Arial, Helvetica, sans-serif; font-size: large;
font-weight: bold; font-style: inherit; font-variant: inherit; text-transform: inherit;
color: #0000FF;">
EIS</td>
<td class="style1">
<asp:TextBox ID="txteis" runat="server" BackColor="White"
BorderColor="#FF3300"
BorderStyle="Ridge" Font-Bold="False" Font-
Overline="False"></asp:TextBox>
</td>
<td>
<asp:Label ID="lbleis" runat="server" Text="Label"
ViewStateMode="Disabled"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="Silver" class="style2"
style="font-family: Arial, Helvetica, sans-serif; font-size: large;
font-weight: bold; font-style: inherit; font-variant: inherit; text-transform: inherit;
color: #0000FF;">
PROJECT</td>
<td class="style1">
<asp:TextBox ID="txtproject" runat="server" BackColor="White"
BorderColor="#FF3300" BorderStyle="Ridge" Font-Bold="False"
Font-Overline="False"></asp:TextBox>
</td>
<td>
<asp:Label ID="lblproject" runat="server" Text="Label"
ViewStateMode="Disabled"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
&nbsp;</td>
<td class="style1">
<asp:Button ID="btngrade" runat="server" Text="Show My Grade" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Practical 5.aspx.vb
Public Class practical_5
Inherits System.Web.UI.Page

Protected Sub btngrade_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btngrade.Click
If Convert.ToInt16(txtasp.Text) < 0 Or Convert.ToInt16(txtasp.Text) > 100 Then
lblasp.Text = "Invalid Marks"
ElseIf Convert.ToInt16(txtasp.Text) <= 100 And Convert.ToInt16(txtasp.Text) > 90
Then
lblasp.Text = "AA"
ElseIf Convert.ToInt16(txtasp.Text) <= 90 And Convert.ToInt16(txtasp.Text) > 80
Then
lblasp.Text = "AB"
ElseIf Convert.ToInt16(txtasp.Text) <= 80 And Convert.ToInt16(txtasp.Text) > 70
Then
lblasp.Text = "BB"
ElseIf Convert.ToInt16(txtasp.Text) <= 70 And Convert.ToInt16(txtasp.Text) > 60
Then
lblasp.Text = "BC"
ElseIf Convert.ToInt16(txtasp.Text) <= 60 And Convert.ToInt16(txtasp.Text) > 50
Then
lblasp.Text = "CC"
ElseIf Convert.ToInt16(txtasp.Text) <= 50 And Convert.ToInt16(txtasp.Text) > 40
Then
lblasp.Text = "DD"
Else
lblasp.Text = "Fail"
End If

If Convert.ToInt16(txteis.Text) < 0 Or Convert.ToInt16(txteis.Text) > 100 Then


lbleis.Text = "Invalid Marks"
ElseIf Convert.ToInt16(txteis.Text) <= 100 And Convert.ToInt16(txteis.Text) > 90
Then
lbleis.Text = "AA"
ElseIf Convert.ToInt16(txteis.Text) <= 90 And Convert.ToInt16(txteis.Text) > 80
Then
lbleis.Text = "AB"
ElseIf Convert.ToInt16(txteis.Text) <= 80 And Convert.ToInt16(txteis.Text) > 70
Then
lbleis.Text = "BB"
ElseIf Convert.ToInt16(txteis.Text) <= 70 And Convert.ToInt16(txteis.Text) > 60
Then
lbleis.Text = "BC"
ElseIf Convert.ToInt16(txteis.Text) <= 60 And Convert.ToInt16(txteis.Text) > 50
Then
lbleis.Text = "CC"
ElseIf Convert.ToInt16(txteis.Text) <= 50 And Convert.ToInt16(txteis.Text) > 40
Then
lbleis.Text = "DD"
Else
lbleis.Text = "Fail"
End If

If Convert.ToInt16(txtjava.Text) < 0 Or Convert.ToInt16(txtjava.Text) > 100 Then


lbljava.Text = "Invalid Marks"
ElseIf Convert.ToInt16(txtjava.Text) <= 100 And Convert.ToInt16(txtjava.Text) >
90 Then
lbljava.Text = "AA"
ElseIf Convert.ToInt16(txtjava.Text) <= 90 And Convert.ToInt16(txtjava.Text) > 80
Then
lbljava.Text = "AB"
ElseIf Convert.ToInt16(txtjava.Text) <= 80 And Convert.ToInt16(txtjava.Text) > 70
Then
lbljava.Text = "BB"
ElseIf Convert.ToInt16(txtjava.Text) <= 70 And Convert.ToInt16(txtjava.Text) > 60
Then
lbljava.Text = "BC"
ElseIf Convert.ToInt16(txtjava.Text) <= 60 And Convert.ToInt16(txtjava.Text) > 50
Then
lbljava.Text = "CC"
ElseIf Convert.ToInt16(txtjava.Text) <= 50 And Convert.ToInt16(txtjava.Text) > 40
Then
lbljava.Text = "DD"
Else
lbljava.Text = "Fail"
End If

If Convert.ToInt16(txtproject.Text) < 0 Or Convert.ToInt16(txtproject.Text) > 100


Then
lblproject.Text = "Invalid Marks"
ElseIf Convert.ToInt16(txtproject.Text) <= 100 And
Convert.ToInt16(txtproject.Text) > 90 Then
lblproject.Text = "AA"
ElseIf Convert.ToInt16(txtproject.Text) <= 90 And
Convert.ToInt16(txtproject.Text) > 80 Then
lblproject.Text = "AB"
ElseIf Convert.ToInt16(txtproject.Text) <= 80 And
Convert.ToInt16(txtproject.Text) > 70 Then
lblproject.Text = "BB"
ElseIf Convert.ToInt16(txtproject.Text) <= 70 And
Convert.ToInt16(txtproject.Text) > 60 Then
lblproject.Text = "BC"
ElseIf Convert.ToInt16(txtproject.Text) <= 60 And
Convert.ToInt16(txtproject.Text) > 50 Then
lblproject.Text = "CC"
ElseIf Convert.ToInt16(txtproject.Text) <= 50 And
Convert.ToInt16(txtproject.Text) > 40 Then
lblproject.Text = "DD"
Else
lblproject.Text = "Fail"
End If

lblasp.Visible = True
lbljava.Visible = True
lbleis.Visible = True
lblproject.Visible = True
End Sub
End Class

SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 6
AIM : Create a Simple calculator with validations and details

pract 6.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="pract 6.aspx.vb"
Inherits="Practical6.pract_6" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
No 1 ::</td>
<td>
<asp:TextBox ID="txtno1" runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtno1" ErrorMessage="Invalid Number"
ForeColor="Red"
MaximumValue="10000" MinimumValue="0"
Type="Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td>
No 2 ::</td>
<td>
<asp:TextBox ID="txtno2" runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="RangeValidator2" runat="server"
ControlToValidate="txtno2" ErrorMessage="Invalid Number"
ForeColor="Red"
MaximumValue="10000" MinimumValue="0"
Type="Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td>
Operator ::</td>
<td>
<asp:DropDownList ID="drpOp" runat="server">
<asp:ListItem>+</asp:ListItem>
<asp:ListItem>-</asp:ListItem>
<asp:ListItem Value="*"></asp:ListItem>
<asp:ListItem>/</asp:ListItem>
</asp:DropDownList>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnclick" runat="server" Text="Find Answer"
Width="107px" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Answer ::</td>
<td>
<asp:TextBox ID="txtans" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

pract 6.aspx.vb
Public Class pract_6

Inherits System.Web.UI.Page

Protected Sub btnclick_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnclick.Click
If (drpOp.Text = "+") Then
txtans.Text = Int(txtno1.Text) + Int(txtno2.Text)
ElseIf (drpOp.Text = "-") Then
txtans.Text = Int(txtno1.Text) - Int(txtno2.Text)
ElseIf (drpOp.Text = "*") Then
txtans.Text = Int(txtno1.Text) * Int(txtno2.Text)
Else
txtans.Text = Int(txtno1.Text) / Int(txtno2.Text)
End If
End Sub
End Class
SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
x PRACTICAL: 7
AIM : Create a web page using the concept of cascading style sheets in
ASP.NET

Style.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Styles.aspx.vb"
Inherits="Practical7.Styles" %>

<!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></title>
<link rel="Stylesheet" type="text/css" href="Sample.css" />
<style type="text/css">
h1
{
color: Green;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="80%" style="background-color: White;" align="center">
<tr>
<td>
<center>
<h1>
...Welcome to Style Sheet World...
</h1>
</center>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Style.aspx.vb
Public Class Styles
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

End Class
SCREENSHOTS:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 8
AIM : Create a web page using the concept of Theme & Skin in ASP.NET

ThemeDemo.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="ThemeDemo.aspx.vb"
Inherits="Practical8ThemeSkin.ThemeDemo" Theme="Theme1" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td align="center" colspan="3" style="font-size:
40px">
Theme 1</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server"
Text="Username" Font-Bold="true" ForeColor="Azure"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server"
Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"
EnableTheming="false"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="Button1" runat="server"
Text="Login" />
</td>
<td>
<asp:Button ID="Button3" runat="server"
Text="Default Button"
EnableTheming="False" />
</td>
</tr>
<tr>
<td align="center" colspan="3" style="font-size:
40px">
Theme 2</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>

<td>
<asp:Label ID="Label3" runat="server"
Text="Username"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server"
Text="Password" EnableTheming="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox4" SkinID="second"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="Button2" runat="server"
Text="Login" />
</td>
<td>
<asp:Button ID="Button4" runat="server"
Text="Default Button" />
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

TextBox.Skin code
<asp:TextBox
ForeColor="Violet"
BackColor="Gray"
runat="server"
/>
<asp:TextBox
SkinId="second"
ForeColor="White"
BackColor="Blue"
runat="server"
/>

Label.Skin code
<asp:Label
runat="server"
Font-Bold="true"
ForeColor="Azure"
BackColor="Black"
/>

Button.Skin code
<asp:Button
runat="server"
BackColor="Teal"
ForeColor="White"
/>

ThemeDemo.aspx.vb code
Public Class ThemeDemo
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

End Class
Output screenshots:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 9
AIM : Create Home page of your website using master page concept
Sample.aspx code
<%@ Page Title="" Language="vb" AutoEventWireup="false"
MasterPageFile="~/MyMasterPage.Master" CodeBehind="Sample.aspx.vb"
Inherits="Practical9.Sample" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<p>
Welcome to our website...</p>
<p>
</p>
</asp:Content>

MyMaster.master code
<%@ Master Language="VB" AutoEventWireup="false"
CodeBehind="MyMasterPage.master.vb"
Inherits="Practical9.MyMasterPage" %>

<!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></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td align="center" colspan="3">
<asp:Menu ID="Menu1" runat="server"
BackColor="#003366" BorderStyle="Solid" DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="14pt"
ForeColor="#99CCFF" Orientation="Horizontal"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#284E98"
ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#B5C7DE" />
<DynamicSelectedStyle BackColor="#507CD1" />
<Items>
<asp:MenuItem Text="Home"
Value="Home"></asp:MenuItem>
<asp:MenuItem Text="Contact Us"
Value="Contact Us"></asp:MenuItem>
<asp:MenuItem Text="About Us" Value="About
Us"></asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#284E98"
ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px"
VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#507CD1" />
</asp:Menu>
<br />
</td>
</tr>
</table>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">
</asp:ContentPlaceHolder>
<table>
<tr>
<td align="center" colspan="3">
Useful Links
</td>
</tr>
<tr align="center">
<td>
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="http://www.google.com">Google</asp:HyperLink>
</td>
<td>
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="http://en.wikipedia.com">Wikipedia</asp:HyperLink>
</td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://www.dictionary.com">Dictionary</asp:HyperLink>
</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Sample.aspx.vb code
Public Class Sample
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

End Class

Output screenshots:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 10
AIM: Create a simple web application to illustrate the concept of
nesting master page in ASP.NET

FacultyHome.aspx code
<%@ Page Title="" Language="vb" AutoEventWireup="false"
MasterPageFile="~/SideMenu.master" CodeBehind="FacultyHome.aspx.vb"
Inherits="Practical10.FacultyHome" %>

StudentHome.aspx code
<%@ Page Title="" Language="vb" AutoEventWireup="false"
MasterPageFile="~/TopMenus.Master" CodeBehind="StudentHome.aspx.vb"
Inherits="Practical10.StudentHome" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<p>
Welcome Student...</p>
</asp:Content>

SideMenu.master code
<%@ Master Language="VB" MasterPageFile="~/TopMenus.Master"
AutoEventWireup="false"
CodeBehind="SideMenu.master.vb" Inherits="Practical10.SideMenu" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<asp:Panel ID="pnl" runat="server">
<table width="90%" align="center">
<tr>
<td>
<table>
<tr>
<td>
<a href="http://www.gmail.com">Add/Update
Result</a>
</td>
</tr>
</table>
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
</asp:Content>

TopMenu.master code
<%@ Master Language="VB" AutoEventWireup="false"
CodeBehind="TopMenus.master.vb" Inherits="Practical10.TopMenus" %>

<!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></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://www.google.com">Change
Password</asp:HyperLink>
</td>
<td>
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="http://www.google.com">View
Result</asp:HyperLink>
</td>
<td>
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="http://www.google.com">Log
Out</asp:HyperLink>
</td>
</tr>
</table>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

Output screenshots:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 11
AIM : Develop a web page to implement the concept of state
management using Cookies
Login.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Login.aspx.vb" Inherits="Practical11Cookies.Login" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Username</td>
<td>
<asp:TextBox ID="txtUserName"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:CheckBox ID="chkRemember" runat="server"
Text="Remember Me" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnLogin" runat="server"
Text="Login" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Login.aspx.vb code
Public Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
If Page.IsPostBack = False Then
txtUserName.Text =
Request.Cookies("myFirstCookie").Values("username")
End If
Catch ex As Exception
txtUserName.Text = ""
End Try
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles btnLogin.Click
If chkRemember.Checked = True Then
Dim c As New HttpCookie("myFirstCookie")
c.Expires = Now.AddMinutes(1)
c.Values("username") = txtUserName.Text
Response.Cookies.Add(c)
End If
End Sub
End Class

Output screenshots:
First run:
Running page again gives username from cookie:

After a minute, if we refresh page, output becomes:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 12
AIM : Develop a web page to implement the concept of state
management using Session and Application
Login.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Login.aspx.vb"
Inherits="Practical12ApplicationSession.Login" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
User Id</td>
<td>
<asp:TextBox ID="txtUsername"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Passcode</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnLogin" runat="server"
Text="Login" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Home.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Home.aspx.vb"
Inherits="Practical12ApplicationSession.Home" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

Login.aspx.vb code
Public Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles btnLogin.Click
Session.Item("username") = txtUsername.Text
Application.Item("username") = txtUsername.Text
Response.Redirect("Home.aspx")
End Sub
End Class

Home.aspx.vb code
Public Class Home
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Write("Welcome : " & Session.Item("username"))
Response.Write("<br/>Last logged in user : " &
Application.Item("username"))
End Sub
End Class

Output screenshots:
First look at output by first user
First user logging in

First user home page


Second user loggin in

Second user home page


First user home page after refreshing

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 13
AIM: Develop a web page to implement the concept of state
management using ViewState and QueryString

ListOfTopic.aspx code:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="ListOfTopics.aspx.vb"
Inherits="Practical13ViewstateQueryString.ListOfTopics" %>

<!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></title>
</head>
<body bgcolor="#99AAFF">
<form id="form1" runat="server">
<div>
<table width="80%" align="center" style="background-
color:white">
<tr>
<td><a href="Tutorial.aspx?chap=1">Chapter-1</a></td>
<td><a href="Tutorial.aspx?chap=2">Chapter-2</a></td>
</tr>
</table>

</div>
<table style="width:100%;">
<tr>
<td>
<asp:Label ID="Label1" runat="server"
Text="no1"></asp:Label>
</td>
<td>
<asp:TextBox ID="Textno1"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<center> <asp:Button ID="Button1" runat="server"
Text="store" /> &nbsp;
<asp:Button ID="Button2" runat="server"
Text="transfer" /></center>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server"
Text="no2"></asp:Label>
</td>
<td>
<asp:TextBox ID="Textno2"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>

ListOfTopic.aspx .vbcode:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles Button1.Click
ViewState("no") = Textno1.Text
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles Button2.Click
Textno2.Text = ViewState("no")
End Sub
End Class
Output screenshots:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 14
AIM: Create a web application using Global.asax file which will count
the number of visitors on web page.

OnlineVisitorCntPage.aspx code:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="OnlineVisitorCntPage.aspx.vb"
Inherits="GlobalPract.OnlineVisitorCntPage" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>

OnlineVisitorCntPage.aspx .vb code:


Public Class OnlineVisitorCntPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Session.Timeout = 1
Response.Write("Online :" & Application.Item("oCnt"))
Response.Write("Visitors :" & Application.Item("vCnt"))
End Sub
End Class

Global.asax code:
Imports System.Web.SessionState
Public Class Global_asax
Inherits System.Web.HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when the application is started
Application.Item("vCnt") = 0
Application.Item("oCnt") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Application.Item("vCnt") =
Convert.ToInt16(Application.Item("vCnt")) + 1
Application.Item("oCnt") =
Convert.ToInt16(Application.Item("oCnt")) + 1
End Sub

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As


EventArgs)
' Fires at the beginning of each request
End Sub

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal


e As EventArgs)
' Fires upon attempting to authenticate the use
End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As


EventArgs)
' Fires when an error occurs
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)


' Fires when the session ends
Application.Item("oCnt") =
Convert.ToInt16(Application.Item("oCnt")) - 1
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
End Class
Output screenshots:
First user, first run
After one minute, 2nd user finds output like this:

After one minutes, 1st user finds:

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 15
AIM: Use various tags in Web.config file for ASP.NET configuration
SampleConfiguration.aspx code:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="SampleConfiguration.aspx.vb"
Inherits="Practical15WebConfig.SampleConfiguration" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:Button ID="Button1" runat="server" Text="Test Stupid URL!!!"
/>
</form>
</body>
</html>

SampleConfiguration.aspx.vb code:
Public Class SampleConfiguration
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load
Response.Write("Version : " &
ConfigurationManager.AppSettings("version") & "<br/>")
Response.Write("Connection string : " &
ConfigurationManager.ConnectionStrings("myConStr").ConnectionString)

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles Button1.Click
MsgBox("Get Ready to go to a page which doesnt exist!!",
MsgBoxStyle.Exclamation)
Response.Redirect("fasdfasdfsadfasdfasdfsadf.aspx")
End Sub
End Class

Web.config code:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application,
please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true"
targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="error.html"
redirectMode="ResponseRedirect">
<error statusCode="404" redirect="error.html"/>
</customErrors>
</system.web>
<connectionStrings >
<add name="myConStr"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Darshak\Documents\HariOm.accdb"/>
</connectionStrings>
<appSettings>
<add key="version" value="1.0" />
</appSettings>
</configuration>
Output screenshots:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 16
AIM: Write sample application to connect to database (connection
object), Fetching and inserting data from database (command object)
and using Data Reader

Inside Database:

DataPage.aspx code:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="DataPage.aspx.vb"
Inherits="Practical16DbConnReadDML.DataPage" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnFetch" runat="server" Text="Fetch Data
using DataReader" />
&nbsp;<asp:Button ID="btnInsert" runat="server" Text="Insert Data" />

</div>
</form>
</body>
</html>

DataPage.aspx.vb code:
Imports System.Data.OleDb

Public Class DataPage


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

Protected Sub btnFetch_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles btnFetch.Click
Dim con As New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Darshak\Documents\HariOm.accdb")
Dim cmd As New OleDbCommand("select * from student", con)
Dim dr As OleDbDataReader
con.Open()
dr = cmd.ExecuteReader()
Response.Write("<div style='margin-
top:30px;position:absolute;'><table width='40%' border=1><tr>")
For i = 0 To dr.FieldCount - 1
Response.Write("<th>" & dr.GetName(i) & "</th>")
Next
Response.Write("</tr>")
While dr.Read
Response.Write("<tr>")
For i = 0 To dr.FieldCount - 1
Response.Write("<td>" & dr(i) & vbTab & "</td>")
Next
Response.Write("</tr>")
End While
Response.Write("</table></div>")
con.Close()
End Sub

Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles btnInsert.Click
Dim con As New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Darshak\Documents\HariOm.accdb")
Dim cmd As New OleDbCommand("insert into student values('" &
InputBox("Enter name") & "','" & InputBox("Enter city") & "'," &
InputBox("Enter semester") & "," & InputBox("Enter marks") & ")", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Data Saved Successfully!", MsgBoxStyle.Information,
"Saved!")
End Sub
End Class

Output screenshots:
First run:
On clicking fetch button:

On clicking Insert button:


After Insertion

Start Date End/Sign Date Faculty Sign Remarks/Grade


PRACTICAL: 17
AIM: Create a Web page and test the connectivity of your database with
biodata form in exercise 1. If connected, display the message that
connection with database is successful, and redirect the user to his
homepage
Login.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Login.aspx.vb" Inherits="Practical17.Login" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Student Name:</td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnCheck" runat="server"
Text="Check Name" />
</td>
<td>
&nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Home.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Home.aspx.vb" Inherits="Practical17.Home" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Welcome home...</div>
</form>
</body>
</html>

Login.aspx.vb code
Imports System.Data.OleDb

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

Protected Sub btnCheck_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles btnCheck.Click
Dim con As New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Darshak\Documents\HariOm.accdb")
Dim ad As New OleDbDataAdapter("select * from student where
sname='" & TextBox1.Text & "'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
MsgBox("Connection Successful!", MsgBoxStyle.Information,
"Welcome")
Response.Redirect("Home.aspx")
Else
MsgBox("Invalid Name", MsgBoxStyle.OkOnly, "Err")
End If
End Sub
End Class

Home.aspx.vb code
Public Class Home
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

End Class
Output screenshots:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 18
AIM: Create a Web page and test the connectivity of your database with
biodata form in exercise 1. If connected, display the message that
connection with database is successful, and redirect the user to his
homepage
Inside Database:

Login.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Login.aspx.vb" Inherits="Practical17.Login" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Student Name:</td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
student&nbsp; password</td>
<td>
<asp:TextBox ID="txtpassword" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
<p>
<asp:Button ID="btnCheck" runat="server" Text="Log
In" />
</p>
</form>
</body>
</html>

Home.aspx code
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Home.aspx.vb" Inherits="Practical17.Home" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Welcome home...</div>
</form>
</body>
</html>

Login.aspx.vb code
Imports System.Data.OleDb

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

Protected Sub btnCheck_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles btnCheck.Click
Dim con As New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Darshak\Documents\HariOm.accdb")
Dim ad As New OleDbDataAdapter("select * from student where
sname='" & TextBox1.Text & "' and password='" & txtpassword.Text &
"'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
MsgBox("Connection Successful!", MsgBoxStyle.Information,
"Welcome")
Response.Redirect("Home.aspx")
Else
MsgBox("Invalid Name", MsgBoxStyle.OkOnly, "Err")
End If
End Sub
End Class

Home.aspx.vb code
Public Class Home
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load
End Sub
End Class

Output screenshots:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 19
AIM : Create a web page to insert user biodata information with all
validations in to the database

Biodata.aspx
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="BioData.aspx.vb" Inherits="Practical19.BioData" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
First Name</td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Enter First Name"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Last Name</td>
<td>
<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2"
ErrorMessage="Enter Last Name"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Birthdate</td>
<td>
<asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3"
ErrorMessage="Enter Birthdate"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Hometown</td>
<td>
<asp:TextBox ID="TextBox4"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox4"
ErrorMessage="Enter Hometown"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Marital Status</td>
<td>
<asp:RadioButton ID="rdoNeverMarried"
runat="server" Checked="True"
GroupName="maritalStatus" Text="Never Married"
/>
<asp:RadioButton ID="rdoMarried" runat="server"
GroupName="maritalStatus"
Text="Married" />
<asp:RadioButton ID="rdoDivorced" runat="server"
GroupName="maritalStatus"
Text="Divorced" />
<asp:RadioButton ID="rdoWidow" runat="server"
GroupName="maritalStatus"
Text="Widow" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Age</td>
<td>
<asp:TextBox ID="TextBox5"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="RangeValidator1"
runat="server"
ControlToValidate="TextBox5"
ErrorMessage="Invalid Age" ForeColor="Red"
MaximumValue="100" MinimumValue="0"
Type="Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td>
Hobby</td>
<td>
<asp:TextBox ID="TextBox6"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator6" runat="server"
ControlToValidate="TextBox6"
ErrorMessage="Enter Hobby"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Current City</td>
<td>
<asp:TextBox ID="TextBox7"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator7" runat="server"
ControlToValidate="TextBox7"
ErrorMessage="Enter Current City"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save
Data" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>
Biodata.aspx.vb
Imports System.Data.OleDb

Public Class BioData


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Me.Load

End Sub

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As


EventArgs) Handles btnSave.Click
Dim marStatus As String
If rdoNeverMarried.Checked Then
marStatus = "Single"
ElseIf rdoMarried.Checked Then
marStatus = "Married"
ElseIf rdoDivorced.Checked Then
marStatus = "Divorced"
Else
marStatus = "Widow"
End If
Dim con As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|
DataDirectory|\BioDataDb.mdb")
Dim cmd As New OleDbCommand("insert into userdata values('" &
TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','"
& TextBox4.Text & "','" & marStatus & "','" & TextBox5.Text & "','" &
TextBox6.Text & "','" & TextBox7.Text & "')", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Response.Write("<font color='green'><b>Data Saved Successfully!
</b></font>")
End Sub
End Class
SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 20
AIM : Create a webpage, that allows user to add a new username if
user doesn’t exist in the database. Also create a forgot password link,
to redirect user to set up his new password on authentication

Login.aspx
Imports System.Data.SqlClient

Public Class Register


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnRegister.Click
Try
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim cmd As New SqlCommand("insert into tblLogin values ('" & txtUsrNm.Text &
"','" & txtUsrPw.Text & "','" & txtHint.Text & "')", con)
Dim ds As New DataSet
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Profile Created Successfully!", MsgBoxStyle.Information, "Done!")
Response.Redirect("Login.aspx")
Catch ex As Exception
Response.Write("<font color='red'>Can't Register!</font>")
End Try
End Sub
End Class

Login.aspx.vb
Imports System.Data.SqlClient

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnLogin.Click
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin where usrnm='" &
txtUsrNm.Text & "' and usrpw='" & txtUsrPw.Text & "'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
Response.Redirect("Home.aspx")
Else
Response.Write("<font color='red'>Invalid Username/Password</font>")
End If
End Sub
End Class

Register.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Register.aspx.vb"
Inherits="Practical20.Register" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Username</td>
<td>
<asp:TextBox ID="txtUsrNm" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox ID="txtUsrPw" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Confirm Password</td>
<td>
Page #: 101 | Government Polytechnic, Gandhinagar

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


TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Hint</td>
<td>
<asp:TextBox ID="txtHint" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnRegister" runat="server" Text="Register" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Register.aspx.vb
Imports System.Data.SqlClient

Public Class Register


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnRegister.Click
Try
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim cmd As New SqlCommand("insert into tblLogin values ('" & txtUsrNm.Text &
"','" & txtUsrPw.Text & "','" & txtHint.Text & "')", con)
Dim ds As New DataSet
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Profile Created Successfully!", MsgBoxStyle.Information, "Done!")

Web Programming using ASP.Net Practicals


Response.Redirect("Login.aspx")
Catch ex As Exception
Response.Write("<font color='red'>Can't Register!</font>")
End Try
End Sub
End Class

ForgotPwd.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ForgotPwd.aspx.vb"
Inherits="Practical20.ForgotPwd" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Enter Username</td>
<td>
<asp:TextBox ID="txtUsrNm" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnShowHint" runat="server" Text="Show Hint" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:Label ID="lblHint" runat="server" Font-Bold="True"
ForeColor="#009933"></asp:Label>
</td>
<td colspan="2">
<asp:LinkButton ID="lnkLogin" runat="server"
PostBackUrl="~/Login.aspx">Back to Login</asp:LinkButton>
</td>
</tr>
</table>

</div>
</form>
</body>
</html>

ForgotPwd.aspx.vb
Imports System.Data.SqlClient

Public Class ForgotPwd


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnShowHint_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnShowHint.Click
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin where usrnm='" &
txtUsrNm.Text & "'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
lblHint.Text = ds.Tables(0).Rows(0).Item("hint").ToString
Else
Response.Write("<font color='red'>Invalid Username!</font>")
End If
End Sub
End Class

Home.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Home.aspx.vb"
Inherits="Practical20.Home" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Welcome Home...</div>
</form>
</body>
</html>
Home.aspx.vb
Public Class Home
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

End Class
SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 21
AIM : Create a webpage to display the information about user on his
homepage once he has logged in through the login form

Login.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"
Inherits="Practical21.Login" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Username</td>
<td>
<asp:TextBox ID="txtUsrNm" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox ID="txtUsrPw" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnLogin" runat="server" Text="Login" />
</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Login.aspx.vb
Imports System.Data.SqlClient

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnLogin.Click
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin where usrnm='" &
txtUsrNm.Text & "' and usrpw='" & txtUsrPw.Text & "'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
Session.Item("usrnm") = txtUsrNm.Text
Response.Redirect("Home.aspx")
Else
Response.Write("<font color='red'>Invalid Username/Password</font>")
End If
End Sub
End Class

Home.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Home.aspx.vb"
Inherits="Practical21.Home" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
<asp:Label ID="lblUserName" runat="server"></asp:Label>
</td>
<td>
&nbsp;</td>
<td>
<asp:LinkButton ID="lnkLogOut" runat="server">Log
Out</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblDesignation" runat="server"></asp:Label>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Home.aspx.vb
Imports System.Data.SqlClient

Public Class Home


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Session.Count > 0 Then
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin where usrnm='" &
Session.Item("usrnm") & "'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
lblUserName.Text = "Welcome " & ds.Tables(0).Rows(0).Item("usrnm")
lblDesignation.Text = "Designation : " &
ds.Tables(0).Rows(0).Item("designation")
End If
Else
Response.Redirect("Login.aspx")
End If
End Sub

Protected Sub lnkLogOut_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


lnkLogOut.Click
Session.Clear()
Response.Redirect("Login.aspx")
End Sub
End Class

SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 22
AIM : Write an exercise, to allow the user to ADD, UPDATE, MODIFY his profile once
he has logged into the website using Bound and Unbound Controls

Home.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Home.aspx.vb"
Inherits="Practical22.Home" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:LinkButton ID="lnkBoundDemo" runat="server" PostBackUrl="~/Bound.aspx">Bound


Control Demo</asp:LinkButton>
<br />
<br />
<asp:LinkButton ID="lnkUnboundDemo" runat="server"
PostBackUrl="~/UnBound.aspx">Unbound Control Demo</asp:LinkButton>

</div>
</form>
</body>
</html>

Home.aspx.vb
Public Class Home
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub
End Class

Bound.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Bound.aspx.vb"
Inherits="Practical22.Bound" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" DataKeyNames="UsrNm"
DataSourceID="SqlDataSource1"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="UsrNm" HeaderText="UsrNm"
ReadOnly="True"
SortExpression="UsrNm" />
<asp:BoundField DataField="UsrPw" HeaderText="UsrPw"
SortExpression="UsrPw" />
<asp:BoundField DataField="Hint" HeaderText="Hint"
SortExpression="Hint" />
<asp:BoundField DataField="Designation"
HeaderText="Designation"
SortExpression="Designation" />
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [tblLogin] WHERE [UsrNm] =
@original_UsrNm AND (([UsrPw] = @original_UsrPw) OR ([UsrPw] IS NULL AND @original_UsrPw
IS NULL)) AND (([Hint] = @original_Hint) OR ([Hint] IS NULL AND @original_Hint IS NULL))
AND (([Designation] = @original_Designation) OR ([Designation] IS NULL AND
@original_Designation IS NULL))"
InsertCommand="INSERT INTO [tblLogin] ([UsrNm], [UsrPw], [Hint],
[Designation]) VALUES (@UsrNm, @UsrPw, @Hint, @Designation)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [tblLogin]"
UpdateCommand="UPDATE [tblLogin] SET [UsrPw] = @UsrPw, [Hint] =
@Hint, [Designation] = @Designation WHERE [UsrNm] = @original_UsrNm AND (([UsrPw] =
@original_UsrPw) OR ([UsrPw] IS NULL AND @original_UsrPw IS NULL)) AND (([Hint] =
@original_Hint) OR ([Hint] IS NULL AND @original_Hint IS NULL)) AND (([Designation] =
@original_Designation) OR ([Designation] IS NULL AND @original_Designation IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_UsrNm" Type="String" />
<asp:Parameter Name="original_UsrPw" Type="String" />
<asp:Parameter Name="original_Hint" Type="String" />
<asp:Parameter Name="original_Designation" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="UsrNm" Type="String" />
<asp:Parameter Name="UsrPw" Type="String" />
<asp:Parameter Name="Hint" Type="String" />
<asp:Parameter Name="Designation" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="UsrPw" Type="String" />
<asp:Parameter Name="Hint" Type="String" />
<asp:Parameter Name="Designation" Type="String" />
<asp:Parameter Name="original_UsrNm" Type="String" />
<asp:Parameter Name="original_UsrPw" Type="String" />
<asp:Parameter Name="original_Hint" Type="String" />
<asp:Parameter Name="original_Designation" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Bound.aspx.vb
Public Class Bound
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load

End Sub

End Class

Unbound.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UnBound.aspx.vb"
Inherits="Practical22.UnBound" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
<asp:RadioButton ID="rdoAdd" runat="server" AutoPostBack="True"
GroupName="operation" Text="Add Data" />
</td>
<td>
<asp:RadioButton ID="rdoUpdate" runat="server" AutoPostBack="True"
GroupName="operation" Text="Update Data" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:Panel ID="pnlAdd" runat="server" Visible="False">
<table style="width:100%;">
<tr>
<td>
Name</td>
<td>
<asp:TextBox ID="txtInsName"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Designation</td>
<td>
<asp:TextBox ID="txtInsDesignation"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox ID="txtInsPwd" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Confirm Password</td>
<td>
<asp:TextBox ID="txtInsCnfPwd" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Hint</td>
<td>
<asp:TextBox ID="txtInsHint"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" />
</td>
<td>
&nbsp;</td>
</tr>
</table>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlUpdate" runat="server" Visible="False">
<table style="width:100%;">
<tr>
<td>
Name</td>
<td>
<asp:DropDownList ID="drpFName" runat="server"
AutoPostBack="True">
</asp:DropDownList>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Designation</td>
<td>
<asp:TextBox ID="txtUpdDesignation"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox ID="txtUpdPwd" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Confirm Password</td>
<td>
<asp:TextBox ID="txtUpdCnfPwd" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Hint</td>
<td>
<asp:TextBox ID="txtUpdHint"
runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="btnUpdate" runat="server"
Text="Update" />
</td>
<td>
&nbsp;</td>
</tr>
</table>
</asp:Panel>
</td>
<td>
&nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Unbound.aspx.vb
Imports System.Data.SqlClient

Public Class UnBound


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Page.IsPostBack = False Then
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
drpFName.DataSource = ds.Tables(0)
drpFName.DataValueField = "usrnm"
drpFName.DataTextField = "usrnm"
drpFName.DataBind()
End If
End If
End Sub

Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As


EventArgs) Handles rdoAdd.CheckedChanged
pnlAdd.Visible = True
pnlUpdate.Visible = False
End Sub

Protected Sub rdoUpdate_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)


Handles rdoUpdate.CheckedChanged
pnlAdd.Visible = False
pnlUpdate.Visible = True
End Sub

Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnAdd.Click
Try
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim cmd As New SqlCommand("insert into tblLogin values ('" & txtInsName.Text
& "','" & txtInsPwd.Text & "','" & txtInsHint.Text & "','" & txtInsDesignation.Text &
"')", con)
Dim ds As New DataSet
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("User Added Successfully!", MsgBoxStyle.Information, "Done!")
Response.Redirect("Home.aspx")
Catch ex As Exception
Response.Write("<font color='red'>Can't Add!</font>")
End Try
End Sub

Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnUpdate.Click
Try
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim cmd As New SqlCommand("update tblLogin set usrpw='" & txtUpdPwd.Text &
"',hint='" & txtUpdHint.Text & "',designation='" & txtUpdDesignation.Text & "' where
usrnm='" & drpFName.Text & "'", con)
Dim ds As New DataSet
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Profile Updated Successfully!", MsgBoxStyle.Information, "Done!")
Response.Redirect("Home.aspx")
Catch ex As Exception
Response.Write("<font color='red'>Can't Update!</font>")
End Try
End Sub

Protected Sub drpFName_SelectedIndexChanged(ByVal sender As Object, ByVal e As


EventArgs) Handles drpFName.SelectedIndexChanged
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin where usrnm='" &
drpFName.Text & "'", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count > 0 Then
txtUpdPwd.Text = ds.Tables(0).Rows(0).Item("usrpw")
txtUpdCnfPwd.Text = ds.Tables(0).Rows(0).Item("usrpw")
txtUpdHint.Text = ds.Tables(0).Rows(0).Item("hint")
txtUpdDesignation.Text = ds.Tables(0).Rows(0).Item("designation")
End If
End Sub
End Class
SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
PRACTICAL: 23
AIM : Create a webpage to bind the user data from database into a
gridview dynamically.

GridViewDynamic.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="GridViewDynamic.aspx.vb"
Inherits="Practical23.GridViewDynamic" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width:100%;">
<tr>
<td>
Select Criteria:</td>
<td>
<asp:RadioButton ID="rdoFull" runat="server" AutoPostBack="True"
GroupName="criteria" Text="Full Data" />
</td>
<td>
<asp:RadioButton ID="rdoLimited" runat="server" AutoPostBack="True"
GroupName="criteria" Text="Limited Data(Hide Password)" />
</td>
</tr>
<tr>
<td align="center" colspan="3">
<asp:GridView ID="GridView1" runat="server" CellPadding="4"
ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>

GridViewDynamic.aspx.vb
Imports System.Data.SqlClient

Public Class GridViewDynamic


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub rdoFull_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)


Handles rdoFull.CheckedChanged
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select * from tblLogin", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
End Sub

Protected Sub rdoLimited_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)


Handles rdoLimited.CheckedChanged
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\PractDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim ad As New SqlDataAdapter("select usrnm as Username,hint as Hint,designation
as Designation from tblLogin", con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
End Sub
End Class

SCREENSHOTS:
Start Date End/Sign Date Faculty Sign Remarks/Grade
Page #: 1 | Government Polytechnic, Gandhinagar

ASP.Net Assignments

•Assignment 1

Web Programming using ASP.Net Assignments


Page #: 2 | Government Polytechnic, Gandhinagar

Question : 1

AIM : Design G-mail Login page like WebPage in ASP.Net

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"


Inherits="Question1.Login"
EnableViewState="false" %>

<!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>Google</title>
<link rel="Shortcut Icon" type="image/ico" href="Images/1.png" />
<script language=javascript type="text/javascript">

function processAjaxData() {
this.history.pushState({"html" : "<html><head></head><body>Ram
Ram</body></html>" ,"Darshak")},"","http://localhost:50466/Login.aspx");
/*document.getElementById("content").innerHTML = response.html ;
document.title = response.pageTitle;
window.history.pushState({ "html": response.html, "pageTitle":
response.pageTitle }, "", "http://www.gmail.com");
*/

}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 700px; width: 1345px; margin: -8px;">
<center>
<font size="6"><font color="#3388FF">G</font><font
color="#ee0000">o</font><font
color="yellow">o</font><font color="#3388FF">g</font><font
color="green">l</font><font
color="#ee0000">e</font> </font>
<br />
<br />
<font face="corbel" size="6" color="#666666">One Account. All of
Google.</font><br />
<br />
<br />
<font face="corbel" size="4" color="#656565">Sign in to Continue to
Gmail</font>
<div style="height: 350px; width: 330px; border: none; margin-top: 8px; border-radius: 5px;
box-shadow: 0px 2px 2px lightgray; background-color: #F7F7F7">

Web Programming using ASP.Net Assignments


<div style="height: 100px; width: 120px; background-image:
url('propic.JPG'); border: none;
margin-top: 20px; margin-left: 100px; background-repeat: no-repeat;
position: absolute;">
</div>
<div style="height: 92px; width: 255px; border: none; position: absolute;
margin-top: 170px;
margin-left: 35px;">

<asp:TextBox ID="txtUser" runat="server" Height="40px" Width="250px"


Font-Size="20px"
ForeColor="ActiveCaption" BorderStyle="Solid"
BorderColor="lightgray"></asp:TextBox>
<asp:TextBox ID="txtPass" runat="server" Height="40px" Width="250px"
Font-Size="20px"
ForeColor="ActiveCaption" BorderStyle="Solid"
BorderColor="ActiveCaption"
TextMode="Password"></asp:TextBox>
<hr color="#F7F7F7" />
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/SignIn.PNG" Height="35px"
Width="255px" />

</div>
</div>
<div style="height: 100px; width: 500px; border: none; margin-top: 15px;">
<font face="corbel" size="3" color="#3399ff">create an account</font><br
/>
<br />
<br />
<font face="corbel" size="3" color="#656565">One Google Account for
everything Google</font>
<img src="Services.PNG" alt="services" />
</div>
</center>
</div>
</form>
</body>
</html>
Output Screen:-
Question : 2

AIM : Design Facebook Login page like WebPage in ASP.Net

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="login.aspx.vb"


Inherits="Question2.login" %>

<!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>Welcome to facebook</title>
<link rel="Shortcut Icon" type="image/ico" href="Images/1.png" />
<style type="text/css">
.style3
{
width: 328px;
}
.style4
{
width: 347px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="background-color: #3B5999; margin: -8px; height: 90px; width: 1350;">
<div style="height: 50px; width: 200px; border: none; margin-top: 15px; margin- left: 180px;
position: absolute;">
<font style="font-family:'lucida grande',tahoma,verdana,arial,sans-serif; color: #FFFFFF;" size="7"><strong>facebook</strong></font>
</div>
<div>
<div style="height: 80px; width: 400px; border: none; margin-left: 850px; margin-top: 5px;
position: absolute;">
<table>
<tr>
<td style="color: #F2F2F2"> Email or Phone
</td>
<td style="color: #F2F2F2;"> Password
</td>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtUser" runat="server" Style="border-
radius: 3px; border-color: #F2F2F2;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtPwd" runat="server" Style="border-radius:
3px; border-color: #F2F2F2;"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnLogin" runat="server" Text="Log In"
BackColor="#5F78B0" BorderStyle="None"
ForeColor="White" Style="border-radius: 2px; border-
color: #F2F2F2;" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="chkKeep" runat="server" ForeColor="#003366"
Font-Size="Small" Text="keep me logged in" />
</td>
<td style="color: #003366; font-size: small;">
Forgot Your Password?
</td>
<td>
&nbsp;
</td>
</tr>
</table>
</div>
</div>
</div>
<div style="background-color: #e7ecf2; height: 665px; width: 1350px; margin-top: 8px;
margin-left: -8px;">
<div style="height: 480px; width: 407px; border: none; margin-left: 300px;
margin-top: 20px;
position: absolute;">
<img src="video.PNG" alt="video" />
<center>
<font color="#454545" style="font-family: Gadugi" size="4"><b>
<br />
Turning 10, Thanks to you<br />
</b></font><font style="font-family: Verdana">
<br />
<pre>Our 10<sup>th</sup> Birthday only happened because of all your
<br />Friendships, stories and memories along the way.
<br /> Thank you.
</pre>
</font>
</center>
</div>
<div style="height: 500px; width: 500px; border: none; margin-left: 800px; margin-top: 20px;
position: absolute;">
<font size="6" color="#454545" style="font-family: Calibri;"><b>Sign Up</b></font><br />
<font color="#444444" face="Calibri">It's free and always will be.<br />
<br />
</font>
<table cellspacing="8">
<tr>
<td class="style4">
<asp:TextBox ID="TextBox1" runat="server" BorderColor="#F2F2F2"
BorderStyle="Ridge"
BorderWidth="1px" Height="30px" Width="140px"
ForeColor="Gray" Style="border-radius: 4px;
border-color: #F2F2F2;">&nbsp;First Name</asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" BorderStyle="Ridge"
BorderWidth="1px" Height="30px"
Width="140px" ForeColor="Gray" Style="border-radius: 4px;
border-color: #F2F2F2;">&nbsp;Last Name</asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:TextBox ID="TextBox3" runat="server" BorderColor="#F2F2F2"
BorderStyle="Ridge"
BorderWidth="1px" Height="30px" Width="285px"
ForeColor="Gray" Style="border-radius: 4px;">&nbsp;Your Email</asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:TextBox ID="TextBox4" runat="server" BorderColor="#F2F2F2"
BorderStyle="Ridge"
BorderWidth="1px" Height="30px" Width="285px"
ForeColor="Gray" Style="border-radius: 4px;">&nbsp;Re-enter Email</asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:TextBox ID="TextBox5" runat="server" BorderColor="#F2F2F2"
BorderStyle="Ridge"
BorderWidth="1px" Height="30px" Width="285px"
ForeColor="Gray" Style="border-radius: 4px;">&nbsp;PassWord</asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<font color="#454545" face="corbel">Birthday </font>
</td>
</tr>
<tr>
<td class="style3">
<asp:DropDownList ID="DropDownList1" runat="server"
Style="border-radius: 4px; border-color: #D2D2D2">
<asp:ListItem>Month</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" Style="border-radius: 4px; border-color: #D2D2D2">
<asp:ListItem>Day</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" Style="border-radius: 4px; border-color: #D2D2D2">
<asp:ListItem>Year</asp:ListItem>
</asp:DropDownList>
<font size="1">Why do I need to provide my birthday?</font>
</td>
</tr>
<tr>
<td class="style3">
<asp:RadioButton ID="RadioButton1" runat="server"
GroupName="Gender" Text="Male"
Style="border-radius: 4px;" />&nbsp;
<asp:RadioButton ID="RadioButton2" runat="server"
GroupName="Gender" Text="Female"
Style="border-radius: 4px;" />
</td>
</tr>
<tr>
<td>
<font size="1">By clicking Sign Up, you agree to our Terms and
that you have<br />
read our Data use policy,including our Cookie use.</font>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" BackColor="#5D994B"
ForeColor="White" Height="35px"
Text="Sign Up" Width="140px" Style="border-radius: 4px;"
BorderStyle="None" />
<hr style="background-color: #808080" />
</td>
</tr>
<tr>
<td>
<font size="3">Create a page for celebrity,band or
business.</font>
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
Output Screen:-
Page #: 10 | Government Polytechnic, Gandhinagar

Question : 3

AIM : Design a Webpage with a master Page having menues and submenues

Markup for Program :

Site.Master:

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb"


Inherits="Practical1_NiharBhatt.Site" %>

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


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
Government Polytechnic Gandhinagar
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ <a href="~/Account/Login.aspx" ID="HeadLoginStatus"
runat="server">Log In</a> ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName"
runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server"
LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu"
EnableViewState="False" IncludeStyleBlock="False"
Orientation="Horizontal"
BackColor="#B5C7DE" DynamicHorizontalOffset="2" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#284E98" StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px"
/>
<DynamicMenuStyle BackColor="#B5C7DE" />

Web Programming using ASP.Net Assignments


<DynamicSelectedStyle BackColor="#507CD1" />
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/Registration.aspx"
Text="Registration"/>
<asp:MenuItem Text="Important Links" Value="ImpLnk">
<asp:MenuItem NavigateUrl="http://www.gtu.ac.in" Text="GTU"
Value="GTU">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.google.co.in"
Text="Google"
Value="Google"></asp:MenuItem>
<asp:MenuItem NavigateUrl="http://en.wikipedia.org"
Text="Wikipedia"
Value="Wikipedia"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#284E98" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#507CD1" />
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">

</div>
</form>
</body>
</html>

Default.aspx:

<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master"


AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="Practical1_NiharBhatt._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">


</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<h2>Welcome to ASP.NET&#39;s 1st Practical.</h2>


<div style="border-style: solid; border-width: medium; height:214px; width:300px;
margin-left:10px; margin-top:50px;">
<asp:Login ID="Login1" runat="server" Height="211px" Width="260px">
</asp:Login>
</div>
</asp:Content>
Registration.aspx:

<%@ Page Title="Registration" Language="vb" AutoEventWireup="false"


MasterPageFile="~/Site.Master" CodeBehind="Registration.aspx.vb"
Inherits="Practical1_NiharBhatt.Registration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div style="height:540px;width:500px;border:solid;margin-top:50px;margin-left:200px;">

<table style="width:100%;">
<tr><td>
EnrollmentNo</td><td>
<asp:TextBox ID="txtEnrno" runat="server" TabIndex="1"
Wrap="False"></asp:TextBox>
</td><td>
&nbsp;</td>
</tr>
<tr> <td>
Password</td>
<td style="margin-left: 40px">
<asp:TextBox ID="txtPwd" runat="server" TabIndex="2"
TextMode="Password"></asp:TextBox>
</td> <td>
&nbsp;</td>
</tr>
<tr>
<td>
Confirm Password</td <td>
<asp:TextBox ID="txtCnfpwd" runat="server" TabIndex="3"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Address</td>
<td>
<asp:TextBox ID="txtAdd" runat="server" TabIndex="4"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>

<tr>
<td>
MobileNo</td>
<td>
<asp:TextBox ID="txtMob" runat="server" TabIndex="6"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server" TabIndex="7"
TextMode="Email"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Gender</td>
<td>
<asp:RadioButton ID="rdoMale" runat="server" GroupName="Gender"
TabIndex="8"
Text="Male" />
<asp:RadioButton ID="rdoFemale" runat="server" GroupName="Gender"
TabIndex="8"
Text="Female" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
City</td>
<td>
<asp:DropDownList ID="drpCity" runat="server" TabIndex="9">
</asp:DropDownList>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
State</td>
<td>
<asp:ListBox ID="lstState" runat="server"
TabIndex="10"></asp:ListBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr><td>
&nbsp;</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<input id="Reset1" type="reset" value="Reset" /></td>
<td>
&nbsp;</td>
</tr>
</table>
</div>
</asp:Content>
Output Screen:-
Question : 4

AIM : Design a Webpage with a master Page have nested masterpage within it.

Markup for Program :

Site.Master:

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb"


Inherits="Practical1_NiharBhatt.Site" %>

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


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
Government Polytechnic Gandhinagar
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ <a href="~/Account/Login.aspx" ID="HeadLoginStatus"
runat="server">Log In</a> ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName"
runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server"
LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu"
EnableViewState="False" IncludeStyleBlock="False"
Orientation="Horizontal"
BackColor="#B5C7DE" DynamicHorizontalOffset="2" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#284E98" StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px"
/>
<DynamicMenuStyle BackColor="#B5C7DE" />
<DynamicSelectedStyle BackColor="#507CD1" />
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/Registration.aspx"
Text="Registration"/>
<asp:MenuItem Text="Important Links" Value="ImpLnk">
<asp:MenuItem NavigateUrl="http://www.gtu.ac.in" Text="GTU"
Value="GTU">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.google.co.in"
Text="Google"
Value="Google"></asp:MenuItem>
<asp:MenuItem NavigateUrl="http://en.wikipedia.org"
Text="Wikipedia"
Value="Wikipedia"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#284E98" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#507CD1" />
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">

</div>
</form>
</body>
</html>

nest.Master:

<%@ Master Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"


CodeBehind="nest.master.vb" Inherits="Practical1_NiharBhatt.nest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#284E98" StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#B5C7DE" />
<DynamicSelectedStyle BackColor="#507CD1" />
<Items>
<asp:MenuItem Text="Google Apps" Value="Google Apps">
<asp:MenuItem NavigateUrl="http://docx.google.com" Text="Docs"
Value="Docs">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="http://mail.google.com" Text="Gmail"
Value="Gmail">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.youtube.com" Text="Youtube"
Value="Youtube"></asp:MenuItem>
<asp:MenuItem NavigateUrl="http://drive.google.com" Text="Drive"
Value="Drive">
</asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="YAHOO!" Value="YAHOO!">
<asp:MenuItem NavigateUrl="http://www.mail.yahoo.com" Text="Mail"
Value="Mail">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.news.yahoo.com" Text="News"
Value="News">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.search.yahoo.com" Text="Search"
Value="Search"></asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.yahoocricket.com" Text="Cricket"
Value="Cricket"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#284E98" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#507CD1" />
</asp:Menu>
</asp:Content>

Default.aspx:

<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master"


AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="Practical1_NiharBhatt._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">


</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<h2>Welcome to ASP.NET&#39;s 1st Practical.</h2>


<div style="border-style: solid; border-width: medium; height:214px; width:300px; margin-left:10px; margin-top:50px;">
<asp:Login ID="Login1" runat="server" Height="211px" Width="260px">
</asp:Login>
</div>
</asp:Content>

Registration.aspx:

<%@ Page Title="Registration" Language="vb" AutoEventWireup="false"


MasterPageFile="~/Site.Master" CodeBehind="Registration.aspx.vb"
Inherits="Practical1_NiharBhatt.Registration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div style="height:540px;width:500px;border:solid;margin-top:50px;margin-left:200px;">

<table style="width:100%;">
<tr><td>
EnrollmentNo</td><td>
<asp:TextBox ID="txtEnrno" runat="server" TabIndex="1"
Wrap="False"></asp:TextBox>
</td><td>
&nbsp;</td>
</tr>
<tr> <td>
Password</td>
<td style="margin-left: 40px">
<asp:TextBox ID="txtPwd" runat="server" TabIndex="2"
TextMode="Password"></asp:TextBox>
</td> <td>
&nbsp;</td>
</tr>
<tr>
<td>
Confirm Password</td <td>
<asp:TextBox ID="txtCnfpwd" runat="server" TabIndex="3"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Address</td>
<td>
<asp:TextBox ID="txtAdd" runat="server" TabIndex="4"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>

<tr>
<td>
MobileNo</td>
<td>
<asp:TextBox ID="txtMob" runat="server" TabIndex="6"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server" TabIndex="7" TextMode="Email"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Gender</td>
<td>
<asp:RadioButton ID="rdoMale" runat="server" GroupName="Gender"
TabIndex="8"
Text="Male" />
<asp:RadioButton ID="rdoFemale" runat="server" GroupName="Gender"
TabIndex="8"
Text="Female" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
City</td>
<td>
<asp:DropDownList ID="drpCity" runat="server" TabIndex="9">
</asp:DropDownList>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
State</td>
<td>
<asp:ListBox ID="lstState" runat="server" TabIndex="10"></asp:ListBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr><td>
&nbsp;</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<input id="Reset1" type="reset" value="Reset" /></td>
<td>
&nbsp;</td>
</tr>
</table>
</div>
</asp:Content>

Output Screen:-
Question : 5

AIM : Design a Simple Login page where UserId from these page is passed to
Home page with a Welcome message and UserId.

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"


Inherits="Question5.Login" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<center>
<div>
<div style="height:230px;width:300px;border-radius:10px;margin-top:185px;box-
shadow:1px 1px 1px 1px #454545;">
<table cellpadding="5">
<tr>
<td colspan="2" align="center">
<font size="6" face="Comic sans MS" color="#454545">Log
in</font></td>

</tr>
<tr>
<td>
<font size="4">Username</font></td>
<td>
<asp:TextBox ID="txtUser" runat="server" Height="35px" Width="200px" Font-Size="20px" ForeColor="#454545"></asp:TextBox>
</td>

</tr>
<tr>
<td>
<font size="4">Password</font></td>
<td>
<asp:TextBox ID="txtPwd" runat="server" Height="35px" Width="200px" Font-Size="20px" ForeColor="#454545"
TextMode="Password"></asp:TextBox>
</td>

</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnLogin" runat="server" BackColor="#4B8BF5"
BorderStyle="Solid"
Font-Bold="True" Font-Italic="False" Font-Names="Calibri" Font-
Size="Medium"
ForeColor="White" Height="35px" Text="Login" Width="262px"
BorderColor="#4B8BF5" BorderWidth="1px" />
</td>

</tr>
</table>
</div>
</div>
</center>
</form>
</body>
</html>

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Destination.aspx.vb" Inherits="Question5.Destination" %>

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

<html xmlns="">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<center><asp:Label ID="lblUser" runat="server" Font-Bold="True"


Font-Names="Comic Sans MS" Font-Size="Larger" ForeColor="#35001B"
></asp:Label></center>

</div>
</form>
</body>
</html>
Login.aspx.vb :

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnLogin.Click

Session.Item("Username") = txtUser.Text
Response.Redirect("Destination.aspx")
End Sub
End Class

Destination.aspx.vb :

Public Class Destination


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


lblUser.Text = "Welcome " & Session.Item("Username") End Sub

End Class
Output Screen:-
Question : 6

AIM : Write a Application where all State management options are used with
fairly appropriate example.

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"


Inherits="Question6.Login" %>

<!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">
<link rel="Shortcut Icon" type="image/ico" href="Images/6i.png" />
<title>Practical-6</title>
</head>
<body>
<form id="form1" runat="server">
<center>
<div>
<div style="height: 380px; width: 300px; border-radius: 10px; margin-top:
185px;
box-shadow: 1px 1px 1px 1px #454545;">
<table cellpadding="5">
<tr>
<td colspan="2" align="center">
<font size="6" face="Comic sans MS" color="#454545">Log
in</font>
</td>
</tr>
<tr>
<td>
<font size="4">Username</font>
</td>
<td>
<asp:TextBox ID="txtUser" runat="server" Height="35px" Width="200px" Font-Size="20px"
ForeColor="#454545"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<font size="4">Password</font>
</td>
<td>
<asp:TextBox ID="txtPwd" runat="server" Height="35px" Width="200px" Font-Size="20px"
ForeColor="#454545" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Enter Image Text :
</td>
<td>
<asp:Image ID="Image1" runat="server" />
<asp:Image ID="Image2" runat="server" />
<asp:Image ID="Image3" runat="server" />
<asp:Image ID="Image4" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:TextBox ID="txtCaptcha" runat="server" Font-Size="15px"
Height="31px" Width="160px"></asp:TextBox>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Label ID="Label1" runat="server" Font-Names="Arial"
Font-Size="10pt" ForeColor="#990000"
Text="Image Text Mismatch!!!"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:CheckBox ID="chkRemember" runat="server" Font-
Names="cursive" Font-Size="Medium"
Text=" Remember Me" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnLogin" runat="server" BackColor="#4B8BF5"
BorderStyle="Solid"
Font-Bold="True" Font-Italic="False" Font-Names="Calibri"
Font-Size="Medium"
ForeColor="White" Height="35px" Text="Login"
Width="262px" BorderColor="#4B8BF5"
BorderWidth="1px" />
</td>
</tr>
</table>
</div>
</div>
</center>
</form>
</body>
</html>

Destination.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Destination.aspx.vb"
Inherits="Question6.Destination" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-top:0px;height:20px;">
<center>
<div style="margin-left: 1300px; border: none; width: 50px;">
<asp:Linkbutton ID="lnkLogOut" runat="server"
>LogOut</asp:Linkbutton></div>
<br />
<asp:Label ID="lblUser" runat="server" Font-Bold="True" Font-Names="Comic
Sans MS"
Font-Size="Larger" ForeColor="#35001B"></asp:Label>
<br />
<br />
<table cellpadding="10" border="1">
<tr>
<td align="center">
<font size="5" color="#454545">Test</font>
</td>
<td colspan="3" align="center">
<font size="5" color="#454545">Find Definations</font>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnkTest" runat="server">Give
Test</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkEnt"
runat="server">Enterprise</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkErp" runat="server">ERP</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkBE" runat="server">Business
Engineering</asp:LinkButton>
</td>
</tr>
</table>
</center>
</div>
<center>
<div style="height: 20px; width: 200px; border: none; margin-top: 605px;">
<asp:Label ID="lblLastLogged" runat="server"></asp:Label>
</div>
</center>
</form>
</body>
</html>

Test.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb"


Inherits="Question6.Test" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="50%" align="center">
<tr>
<td>Test Started On:</td>
<td>
<asp:Label ID="lblStart" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>Time Spent till Last Question :</td>
<td>
<asp:Label ID="lblDuration" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2"><asp:Label ID="lblQuestion" runat="server"
Text="Question-1"></asp:Label></td>
</tr>
<tr>
<td align="right" colspan="2"><asp:Button ID="btnNext" runat="server"
Text="Next" /></td>
</tr>
<tr>
<td align="center" colspan="2"><asp:LinkButton ID="lnkHome"
runat="server"
Text="Home"
PostBackUrl="~/Destination.aspx"></asp:LinkButton></td>
</tr>
</table>

</div>
</form>
</body>
</html>

Login.aspx.vb :

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

If IsPostBack = False Then

Try
txtUser.Text = Request.Cookies("myCookie").Values("Username")
Catch ex As Exception

End Try

bel1.Visible = False
nerateCaptcha() End If
d Sub

otected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click

chkRemember.Checked = True Then


m c As New HttpCookie("myCookie") c.Values("Username") = txtUser.Text c.Expires = Now.AddDays(10) Response.Cookies.Add(c)
d If

HiddenField1.Value = txtCaptcha.Text Then Session.Item("Username") = txtUser.Text Application("lastLogged") = txtUser.Text Response.Redirect("Destination.aspx


se
bel1.Visible = True generateCaptcha()
d If End Sub
ivate Sub generateCaptcha()

m r As New Random Dim n As String

= r.Next(0, 10) n &= r.Next(0, 10) n &= r.Next(0, 10) n &= r.Next(0, 10)
Image1.ImageUrl = "~/Images/" & n.Substring(0, 1) & ".png"
Image2.ImageUrl = "~/Images/" & n.Substring(1, 1) & ".png"
Image3.ImageUrl = "~/Images/" & n.Substring(2, 1) & ".png"
Image4.ImageUrl = "~/Images/" & n.Substring(3, 1) & ".png"

HiddenField1.Value = n
End Sub

End Class

Destination.aspx.vb :

Public Class Destination


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Session.Count > 0 Then
lblUser.Text = "Welcome " & Session.Item("Username")
lblLastLogged.Text = "Last Logged in User: " & Application("lastLogged")
Else
Response.Redirect("Login.aspx")
End If

End Sub
Protected Sub lnkTest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
lnkTest.Click
response.redirect("Test.aspx")
End Sub

Protected Sub lnkEnt_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


lnkEnt.Click
Response.Redirect("Defination.aspx?Def=" & lnkEnt.Text)
End Sub

Protected Sub lnkErp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


lnkErp.Click
Response.Redirect("Defination.aspx?Def=" & lnkErp.Text)
End Sub

Protected Sub lnkBE_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


lnkBE.Click
Response.Redirect("Defination.aspx?Def=" & lnkBE.Text)
End Sub

Protected Sub lnkLogOut_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


lnkLogOut.Click
Session.Clear()
Response.Redirect("login.aspx")
End Sub
End Class
Test.aspx.vb :

Public Class Test


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Session.Count > 0 Then
If Page.IsPostBack = False Then
ViewState("startTime") = Now
End If
lblStart.Text = ViewState("startTime")
Dim t As New Date(Now.Year, Now.Month, Now.Day,
ViewState("startTime").ToString.Split(" ")(1).Split(":")(0),
ViewState("startTime").ToString.Split(" ")(1).Split(":")(1),
ViewState("startTime").ToString.Split(" ")(1).Split(":")(2))
lblDuration.Text = Now.Subtract(t).Minutes & ":" & Now.Subtract(t).Seconds
Else
Response.Redirect("Login.aspx")
End If

End Sub

Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnNext.Click
If lblQuestion.Text <> "Question-5" Then
lblQuestion.Text = "Question-" & (CInt(lblQuestion.Text.Split("-")(1)) + 1)
Else
Dim t As New Date(Now.Year, Now.Month, Now.Day,
ViewState("startTime").ToString.Split(" ")(1).Split(":")(0),
ViewState("startTime").ToString.Split(" ")(1).Split(":")(1),
ViewState("startTime").ToString.Split(" ")(1).Split(":")(2))
MsgBox("Test is Over!" & vbNewLine & "Time Taken : " &
Now.Subtract(t).Minutes & ":" & Now.Subtract(t).Seconds)
Response.Redirect("Destination.aspx")
End If

End Sub
End Class

Err.htm :

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


<html xmlns="">
<head>
<title></title>
</head>
<body>
<center>
<div>
<font size="6" color="#FF0000" >Invalid URL...</font>
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Destination.aspx" shape="circle">Click here!!</a>
</div>
</center>
</body>
</html>

Output Screen:-
Question : 7

AIM : Design a page and use Regular Expression for Particular Requirements
and show invalid data & Error message

1. Student name must start with “S” letter and followed by 5 digit.

2. Marks Entered must be from 0-70

3. C-Language Identifier

Markup for Program :

Velocity.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Velocity.aspx.vb"
Inherits="Question7.Velocity" %>

<!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>Question-7</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table>
<tr>
<td colspan="2" style="text-align:center;">
<font size="5" color="#454545"> Data Directory </font>
</td>
</tr>
<tr>
<td align="Left">
Enter Student Code:
</td>
<td>
<asp:TextBox ID="txtStdCode" runat="server" Height="35px"
Width="170px"
Font-Size="20px"></asp:TextBox>
</td>
<td align="left">
<asp:RegularExpressionValidator ID="RegularExpressionValidator3"
runat="server"
ErrorMessage="Enter Valid Code"
ControlToValidate="txtStdCode"
ForeColor="Red" SetFocusOnError="True"
ValidationExpression="[sS]\d{5}">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="Left">
Enter Marks:
</td>
<td>
<asp:TextBox ID="txtMarks" runat="server" Height="35px"
Width="170px"
Font-Size="20px"></asp:TextBox>
</td>
<td align="left">
<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
runat="server"
ErrorMessage="Enter Marks between 0-70"
ControlToValidate="txtMarks"
ForeColor="Red" ValidationExpression="[0-6][0- 9]|
70">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="left">
Enter C- language Identifier:
</td>
<td>
<asp:TextBox ID="txtCId" runat="server" Height="35px"
Width="170px"
Font-Size="20px"></asp:TextBox>
</td>
<td align="left">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ErrorMessage="Invalid C Identifier"
ControlToValidate="txtCId"
ForeColor="Red" ValidationExpression="[a-zA-Z_][a-zA-Z0-
9_]{0,30}">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Button ID="btnValidate" runat="server" Height="36px"
Text="Check Validity"
Width="330px" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Correction(s) needed:" ShowMessageBox="True"
ShowSummary="False" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>

Output Screen:-
Start Date End/Sign Date Faculty Sign Remarks/Grade
Page #: 37 | Government Polytechnic, Gandhinagar

ASP.Net Assignments

•Assignment 2

Web Programming using ASP.Net Assignments


Page #: 38 | Government Polytechnic, Gandhinagar

Question : 1

AIM : Write a Application for Online User & Total visitor count.

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"


Inherits="Question1.Login" %>

<!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">
<link rel="Shortcut Icon" type="image/ico" href="Images/6i.png"/>
<title>Practical-6</title>
</head>
<body>
<form id="form1" runat="server">
<center>
<div>
<div style="height: 220px; width: 300px; border-radius: 10px; margin-top:
185px;
box-shadow: 1px 1px 1px 1px #454545;">
<table cellpadding="5">
<tr>
<td colspan="2" align="center">
<font size="6" face="Comic sans MS" color="#454545"
style="font-weight: 700">Log in</font>
</td>
</tr>
<tr>
<td>
<font size="4">Username</font>
</td>
<td>
<asp:TextBox ID="txtUser" runat="server" Height="35px"
Width="200px" Font-Size="20px"
ForeColor="#454545"></asp:TextBox>
</td>
</tr><tr>
<td>
<font size="4">Password</font>
</td><td>
<asp:TextBox ID="txtPwd" runat="server" Height="35px" Width="200px" Font-Size="20px"
ForeColor="#454545" TextMode="Password"></asp:TextBox>
</td>
</tr> <tr>
<td colspan="2" align="center">

Web Programming using ASP.Net Assignments


<asp:Button ID="btnLogin" runat="server" BackColor="#4B8BF5"
BorderStyle="Solid"
Font-Bold="True" Font-Italic="False" Font-Names="Calibri"
Font-Size="Medium"
ForeColor="White" Height="35px" Text="Login"
Width="262px" BorderColor="#4B8BF5"
BorderWidth="1px" />
</td> </tr>
</table>
</div></div>
</center>
</form>
</body>
</html>

Display.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="display.aspx.vb"


Inherits="Question1.display" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center> <asp:Label ID="lblUser" runat="server" Font-Bold="True" Font-Names="Comic
sans MS"
Font-Size="Larger" ForeColor="#663300" ></asp:Label>
<br /><br /> <asp:Label ID="lblVisitor" runat="server" Font-Bold="True" Font-
Names="Comic sans MS"
Font-Size="Larger" ForeColor="#663300" ></asp:Label>
<br />
<asp:Label ID="lblOnline" runat="server" Font-Bold="True" Font-Names="Comic sans
MS"
Font-Size="Larger" ForeColor="#00FF00" ></asp:Label>

</center>

</div>
</form>
</body>
</html>
Code for Program:

Login.aspx.vb :

Public Class Login


Inherits System.Web.UI.Page

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnLogin.Click
Session.Item("user") = txtUser.Text
Response.Redirect("display.aspx")
End Sub
End Class

Display.aspx.vb :

Public Class display


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
lblUser.Text = Session.Item("user")
lblVisitor.Text = "Total Visitor:" & Application("visitor")
lblOnline.Text = "Online User:" & Application("online")
Session.Timeout = 1
End Sub

End Class

Global.asax.vb :
Imports System.Web.SessionState

Public Class Global_asax


Inherits System.Web.HttpApplication

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)


Application("visitor") = 0
Application("online") = 0
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)


Application("visitor") = Application("visitor") + 1
Application("online") = Application("online") + 1
End Sub

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)


End Sub

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)


End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)


End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Application("online") = Application("online") - 1
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)


End Sub
End Class

Output Screen:-
Question : 2

AIM : Write Application which Sends an Email to a particular email ID


whenever any user login to a websites.

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"


Inherits="Question2.Login" %>

<!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">
<link rel="Shortcut Icon" type="image/ico" href="Images/6i.png"/>
<title>Practical-6</title>
<style type="text/css">
.style1
{
width: 281px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<center>
<div>
<div style="height: 220px; width: 300px; border-radius: 10px; margin-top:
185px;
box-shadow: 1px 1px 1px 1px #454545;">
<table cellpadding="5">
<tr>
<td colspan="3" align="center">
<font size="6" face="Comic sans MS" color="#454545"
style="font-weight: 700">Log in</font>
</td>
</tr>
<tr>
<td>
<font size="4">Email</font> </td>
<td class="style1">
<asp:TextBox ID="txtUser" runat="server" Height="35px" Width="200px" Font-Size="20px"
ForeColor="#454545"></asp:TextBox>
</td>
<td class="style1">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtUser" ErrorMessage="Invalid Email"
ForeColor="Red"
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-
.]\w+)*\.\w+([-.]\w+)*">Invalid Email</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<font size="4">Password</font>
</td>
<td class="style1">
<asp:TextBox ID="txtPwd" runat="server" Height="35px"
Width="200px" Font-Size="20px"
ForeColor="#454545" TextMode="Password"></asp:TextBox>
</td>
<td class="style1">
&nbsp;</td>
</tr>
<tr>
<td colspan="3" align="center">
<asp:Button ID="btnLogin" runat="server" BackColor="#4B8BF5"
BorderStyle="Solid"
Font-Bold="True" Font-Italic="False" Font-Names="Calibri"
Font-Size="Medium"
ForeColor="White" Height="35px" Text="Login" Width="262px" BorderColor="#4B8BF5"
BorderWidth="1px" />
</td>
</tr>
</table>
</div>
</div>
</center>
</form>
</body>
</html>

Display.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="display.aspx.vb"


Inherits="Question2.display" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div><center><asp:Label ID="lblUser" runat="server" Font-Bold="True" Font-
Names="Comic sans MS"
Font-Size="Larger" ForeColor="#663300" ></asp:Label>
<br /><br />Please visit ur G-mail Account...
</center>
</div>
</form>
</body>
</html>

Code for Program :

Login.aspx.vb :

Imports System.Net
Imports System.Net.Mail

Public Class Login


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnLogin.Click
Session.Item("user") = txtUser.Text
sendmail(txtUser.Text, "Logged In", "You have logged in with" & txtUser.Text)
Response.Redirect("display.aspx")
End Sub

Sub sendmail(ByVal toAddress As String, ByVal subject As String, ByVal body As


String)
Try
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
smtp.EnableSsl = True
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.Credentials = New NetworkCredential("niharbhatt123@gmail.com",
"samplepassword")
smtp.Timeout = 1000000
smtp.Send("niharbhatt123@gmail.com", toAddress, subject, body)
Catch ex As Exception

End Try
End Sub
End Class

Display.aspx.vb :
Public Class display
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Session.Count > 0 Then
lblUser.Text = Session.Item("user")
Session.Timeout = 20
End If
End Sub
End Class

dbprocess.vb :

Imports System.Data.SqlClient
Imports System.Security.Cryptography
Imports System.Net
Imports System.Net.Mail

Public Class dbprocess


Public Function fetch(ByVal strQuery As String) As DataSet
Try
Dim con As New
SqlConnection(ConfigurationManager.ConnectionStrings("TWcon").ConnectionString)
Dim ad As New SqlDataAdapter(strQuery, con)
Dim ds As New DataSet
con.Open()
ad.Fill(ds)
con.Close()
Return ds
Catch ex As Exception
MsgBox("Operation could not fatched!!", MsgBoxStyle.Critical, "Err!!")
Return Nothing
End Try
End Function
Public Function DML(ByVal strQuery As String) As String
Try
Dim con As New
SqlConnection(ConfigurationManager.ConnectionStrings("TWcon").ConnectionString)
Dim cmd As New SqlCommand(strQuery, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Return "Data Changed Successfully!!"
Catch ex As Exception
Return "Operation could not Performed!!"
End Try
End Function
End Class
Output Screen:-
Question : 3

AIM : Write application which denies access to a websites when Online user
exceed 2 counts.

Markup for Program :

Index.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb"


Inherits="Question3.index" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Welcome...</h1>
</div>
</form>
</body>
</html>

Overload.htm:

<!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>
<title></title>
</head>
<body>
<h1>Serverdown...</h1>
</body>
</html>
Code for Program :

Index.aspx.vb :

Public Class index


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Application("count") > 2 Then
Response.Redirect("Overload.htm")
End If
End Sub

End Class

Global.asax.vb :

Imports System.Web.SessionState

Public Class Global_asax


Inherits System.Web.HttpApplication

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)


Application("count") = 0
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Application("count") = Application("count") + 1


End Sub

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) End Sub

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) Application("count") = Application("count") - 1


End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) End Sub

End Class
Output Screen:-

1st User…

2nd User…

3rd User…
Question : 4

AIM : Write a page which allow to perform insert, update, and delete queries
where result in table data is displayed in a data grid.

Markup for Program :

View.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="View.aspx.vb"


Inherits="Question4.View" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table cellpadding="10" align="center">
<tr>
<td colspan="2">
<font face="Comic sans MS" size="6" color="#454545">Data
Directory</font></td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right"
/>
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White"
/>
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
</td>
</tr>
<tr>
<td colspan="2">
<asp:LinkButton ID="lnkInsert" runat="server">Insert</asp:LinkButton>
<asp:LinkButton ID="lnkUpdate"
runat="server">Update</asp:LinkButton>
<asp:LinkButton ID="lnkDelete"
runat="server">Delete</asp:LinkButton>
</td>
</tr>
<tr>
<td id="lblEmpName">
<asp:Label ID="lblEmpID" runat="server" Text="Employee ID"
Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmpID" runat="server"
Visible="False"></asp:TextBox>
</td>
</tr>
<tr>
<td id="lblEmpName">
<asp:Label ID="lblEmployeeName" runat="server" Text="Employee
Name"
Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmpName" runat="server"
Visible="False"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblDesignation" runat="server" Text="Designation"
Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtDesignation" runat="server"
Visible="False"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCity" runat="server" Text="City"
Visible="False"></asp:Label>
</td>
<td style="font-weight: 700">
<asp:TextBox ID="txtCity" runat="server"
Visible="False"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnInsert" runat="server" Text="Submit"
Visible="False" />
<asp:Button ID="btnUpdate" runat="server" Text="Submit"
Visible="False" />
<asp:Button ID="btnDelete" runat="server" Text="Delete"
Visible="False" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>

Code for Program :

View.aspx.vb :

Imports System.Data.SqlClient
Public Class View
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
Dim obj As New dbProcess
Dim ds = obj.fetch("Select * from Employee")
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()

End Sub

Protected Sub lnkInsert_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


lnkInsert.Click
txtEmpID.Visible = False
txtCity.Visible = True
txtDesignation.Visible = True
txtEmpName.Visible = True
lblCity.Visible = True
lblDesignation.Visible = True
lblEmployeeName.Visible = True
lblEmpID.Visible = False
btnInsert.Visible = True
lnkDelete.Visible = False
lnkUpdate.Visible = False
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
btnInsert.Click

Dim obj As New dbProcess


obj.DML("insert into Employee(EName,Designation,City) values('" & txtEmpName.Text
& "','" & txtDesignation.Text & "','" & txtCity.Text & "')")

txtCity.Visible = False
txtDesignation.Visible = False
txtEmpName.Visible = False
lblCity.Visible = False
lblDesignation.Visible = False
lblEmployeeName.Visible = False
btnInsert.Visible = False
Response.Redirect("view.aspx")
End Sub
Protected Sub lnkUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
lnkUpdate.Click
txtEmpID.Visible = True
lblEmpID.Visible = True
lnkDelete.Visible = False
lnkInsert.Visible = False
lnkUpdate.Visible = False
btnUpdate.Visible = True
btnUpdate.Text = "Select"
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
btnUpdate.Click
If btnUpdate.Text = "Select" Then
txtEmpID.Enabled = False
txtCity.Visible = True
txtDesignation.Visible = True
txtEmpName.Visible = True
lblCity.Visible = True
lblDesignation.Visible = True
lblEmployeeName.Visible = True

If Page.IsPostBack Then
Dim obj As New dbProcess
Dim ds As New DataSet
ds = obj.fetch("Select * from Employee where EmpID = " & txtEmpID.Text)

txtEmpName.Text = ds.Tables(0).Rows(0).Item("EName")
txtDesignation.Text = ds.Tables(0).Rows(0).Item("Designation")
txtCity.Text = ds.Tables(0).Rows(0).Item("City")
btnUpdate.Visible = True
btnUpdate.Text = "Update"
End If
Else
Dim obj As New dbProcess
obj.DML("Update Employee set EName='" & txtEmpName.Text & "',Designation='" &
txtDesignation.Text & "',City='" & txtCity.Text & "' where EmpID='" & txtEmpID.Text &
"'")
Response.Redirect("view.aspx")
End If
End Sub
Protected Sub lnkDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
lnkDelete.Click
lblEmpID.Visible = True
txtEmpID.Visible = True
lnkUpdate.Visible = False
lnkInsert.Visible = False
btnDelete.Visible = True
btnDelete.Text = "Select"
End Sub

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnDelete.Click
If btnDelete.Text = "Select" Then
lblEmpID.Visible = True
txtEmpID.Visible = True
txtEmpID.Enabled = False
txtEmpName.Visible = True
lblEmployeeName.Visible = True
txtDesignation.Visible = True
lblDesignation.Visible = True
txtCity.Visible = True
lblCity.Visible = True

Dim obj As New dbProcess


Dim ds As New DataSet
ds = obj.fetch("Select * from Employee where EmpID=" & txtEmpID.Text)
txtEmpName.Text = ds.Tables(0).Rows(0).Item("EName")
txtDesignation.Text = ds.Tables(0).Rows(0).Item("Designation")
txtCity.Text = ds.Tables(0).Rows(0).Item("City")
btnDelete.Text = "Delete"
Else
Dim obj As New dbProcess
obj.DML("Delete Employee where EmpID=" & txtEmpID.Text)
Response.Redirect("view.aspx")
End If

End Sub
End Class

dbprocess.vb :

Imports System.Data.SqlClient

Public Class dbProcess

Function fetch(ByVal str) As DataSet


Dim con As New SqlConnection("Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\databank.mdf;Integrated
Security=True;User Instance=True")
Dim ad As New SqlDataAdapter(str, con)
Dim ds As New DataSet

con.Open()
ad.Fill(ds)
con.Close()
Return ds
End Function
Sub DML(ByVal str As String)
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\databank.mdf;Integrated Security=True;User Instance=True")
Dim cmd As New SqlCommand(str, con)

con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
End Class
Output Screen:-
Question : 5

AIM : Design and write a code for a page which sort and filters data using data
view and display content in grid view.

Markup for Program :

Login.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Display.aspx.vb"


Inherits="Question5.Display" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table style="width: 100%;">


<tr>
<td>
Order Output by :</td>
<td>
<asp:DropDownList ID="drpOrdering" runat="server">
</asp:DropDownList>
</td>
<td>
<asp:RadioButton ID="rdoAscending" runat="server" GroupName="sort" Text="Ascending" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="sort" Text="Descending" />
</td>
</tr>
<tr>
<td>
Limit Output by :</td>
<td>
<asp:DropDownList ID="drpWhereCondition" runat="server">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem>&lt;</asp:ListItem>
<asp:ListItem>&gt;</asp:ListItem>
<asp:ListItem>&gt;=</asp:ListItem>
<asp:ListItem>&lt;=</asp:ListItem>
<asp:ListItem>=</asp:ListItem>
<asp:ListItem>&lt;&gt;</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtCriteria" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<asp:Button ID="btnShow" runat="server" Height="33px" Text="Show
Data"
Width="218px" />
</td>
</tr>
<tr>
<td align="center" colspan="3">
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4"
ForeColor="Black" GridLines="Horizontal">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black"
HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True"
ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
</td>
</tr>
</table>

</div>
</form>
</body>
</html>

Code for Program :

Display.aspx.vb :
Imports System.Data.SqlClient

Public Class Display


Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
If Not Page.IsPostBack Then
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\TraineeWorld.mdf;Integrated Security=True;Connect Timeout=30;User
Instance=True")
Dim ad As New SqlDataAdapter("Select * from trainee", con)
Dim ds As New DataSet

con.Open()
ad.Fill(ds)
con.Close()

For i = 0 To ds.Tables(0).Columns.Count - 1
drpOrdering.Items.Add(ds.Tables(0).Columns(i).ColumnName)
drpWhereCondition.Items.Add(ds.Tables(0).Columns(i).ColumnName)
Next
End If
End Sub

Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As EventArgs) Handles


btnShow.Click
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\TraineeWorld.mdf;Integrated Security=True;Connect Timeout=30;User
Instance=True")
Dim ad As New SqlDataAdapter("Select * from trainee", con)
Dim ds As New DataSet

con.Open()
ad.Fill(ds)
con.Close()

Dim dv As New DataView(ds.Tables(0))

dv.RowFilter = drpWhereCondition.Text & " " & DropDownList3.Text & " '" &
txtCriteria.Text & "'"
If rdoAscending.Checked = True Then
dv.Sort = drpOrdering.Text
Else
dv.Sort = drpOrdering.Text & " DESC"
End If
GridView1.DataSource = dv
GridView1.DataBind()

End Sub
End Class
Output Screen:-

Start Date End/Sign Date Faculty Sign Remarks/Grade

You might also like