0% found this document useful (0 votes)
21 views23 pages

Jawaharlal Nehru Engineering College: Laboratory Manual

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 23

Jawaharlal Nehru Engineering College

Laboratory Manual

(ASP.NET)

For

S.Y (M.C.A) Students

15, June 2016 – Rev 00 – MCA – ISO 9000 Tech Document

Author JNEC, Aurangabad


FORWARD

It is my great pleasure to present this laboratory manual for S.Y


(M.C.A)engineering students for the subject of ASP.NET. Subject name itself is
expecting what are the advance controls and services that might be used to
develope web applications using Microsoft technology i.e. ASP.NET with code
behind language c# .

As a student, many of you may be wondering with some of the questions in


your mind regarding the subject and exactly what has been tried is to answer
through this manual.

As you may be aware that MGM has already been awarded with ISO 9000
certification and it is our endure to technically equipt our students taking the
advantage of the procedural aspects of ISO 9000 Certification.

Faculty members are also advised that covering these aspects in initial stage
itself, will greatly relived them in future as much of the load will be taken care
by the enthusiasm energies of the students once they are conceptually clear.

Prof. S.D.DESHMUKH
Principal
LABORATORY MANUAL CONTENTS

This manual is intended for the students S.Y (M.C.A) engineering for the
subject of ASP.NET. Subject name itself is expecting what are the advance
controls and services that might be used to develop web applications using
Microsoft technology i.e. ASP.NET with code behind language c#.
In the subject of this manual typically contains practical/Lab Sessions we
have dealt with ASP.NET.

ASP.NET is the next generation ASP, but it's not an upgraded version of ASP.
ASP.NET is an entirely new technology for server-side scripting. It was
written from the ground up and is not backward compatible with classic ASP.

Students are advised to thoroughly go through this manual rather than only
topics mentioned are the key to understanding and conceptual visualization of
theoretical aspects covered in the books.

Good Luck for your Enjoyable Laboratory Sessions

Lect. K. K. Misal
SUBJECT INDEX:

1. Introduction to C#, .net framework, feature, etc.


2. To Study Design of form and Database Connectivity.
3. To state management technique.
4. To study the web server controls of asp.net.
5. Master Page and content page.
6. To study the Validation controls in asp.net.
7. To study the grid view control in asp.net.
8. To study the ADO.net and Stored procedure in asp.net.
9. To study Dynamic link Library.
10. To Study Crystal reports

DOs and DON’T DOs in Laboratory:

1. Do not handle any equipment before reading the instructions/Instruction manuals

2. Read carefully the power ratings of the equipment before it is switched on whether ratings
230 V/50
Hz or 115V/60 Hz. For Indian equipments, the power ratings are normally 230V/50Hz. If you
have equipment with 115/60 Hz ratings, do not insert power plug, as our normal supply is
230V/50 Hz, which will damage the equipment.

3. Observe type of sockets of equipment power to avoid mechanical damage

4. Do not forcefully place connectors to avoid the damage

5. Strictly observe the instructions given by the teacher/Lab Instructor

Instruction for Laboratory Teachers::

1. Submission related to whatever lab work has been completed should be done during the next lab
session. The immediate arrangements for printouts related to submission on the day of practical
assignments.

2. Students should be taught for taking the printouts under the observation of lab teacher.

3. The promptness of submission should be encouraged by way of marking and evaluation patterns
that will benefit the sincere students.
WARMUP EXCERCISES:

What is Internet, web server, browser?

What is client side scripting and server side scripting?

.NET Framework, namespaces, page life cycle, HTML and web controls.

State management techniques.

What are View state, Cookies, Hidden, Querystring?

Difference Session and Application state management technique.

Validation controls.

What is ADO.NET? Different types of ADO.NET objects?


1. Lab Exercises:

[Purpose of this exercise is to introduce c#. You can use Visual Studio .NET
environment to type the program. Execution of program in two ways.
1. Press F5 button OR
1. Write a program in VISUAL STUDIO.NET environment.
2. If VISUAL STUDIO .NET environment then
(i) Right click on Solution Explorer and Select Add New Item.
(ii) Select Console Application.
(iii) Write the code.
(iv) Select page in Solution Explorer =>Right click=>Select View in
Browser to execute.
OR
Press F5 button for execution.
Exercise No1: ( 2 Hours) – 1 Practical

Introduction to C#, framework, feature,etc


Program: Sample program to Demostrate c#
2. Lab Exercises:

[Purpose of this exercise is to introduce c#. You can use Visual Studio
.NET environment to type the program. Execution of program in two ways.
2. Press F5 button OR
3. Right click on ASP.NET page (for e.g.: Default.aspx) and Select “View
Browser” option and select any browser for execution.

Exercise No2: ( 2 Hours) – 1 Practical


Lab Assignment 2: To Study Design of form and Database
Connectivity.
Program: Sample program to Demostrate Insertion of data into
database
3. Lab Exercises:

[Purpose of this exercise is to introduce ASP.NET State management techniques. You


can use Visual Studio .NET environment to type the program. Execution of program
in two ways.
1. Press F5 button OR
2. Right click on ASP.NET page (for eg: Default.aspx) and Select “View Browser”
option and select any browser for execution.

Exercise No3: ( 2 Hours) – 1 Practical


Lab Assignment 3: State management techniques
Program:

Steps:
1. Start a new web site with two web forms. Let Default.aspx and Success.aspx are
two web forms.
2. Design Default.aspx page with fields Employee name, address, contact no, email
id and a submit button.
3. After filling all information, it should be displayed on Success.aspx page using
Query String or Session state management technique.
4. Code using Query String as shown below:
4. Lab Exercises:

[Purpose of this exercise is to use advance web controls. You can use Visual Studio
.NET environment to type the program. Execution of program in two ways.
1. Press F5 button OR
2. Right click on ASP.NET page (for eg: Default.aspx) and Select “View Browser”
option and select any browser for execution.

Exercise No4: ( 2 Hours) – 1 Practical


Lab Assignment 4: To study web server control in asp.net
Program: Hyperlink, Linkbutton and Fileupload controls from toolbox.

Steps:
1. Start a new web site with two web forms. Let Default.aspx and Default2.aspx
are two web forms.
2. Take Hyperlink, Linkbutton and Fileupload controls from toolbox.
3. Follow the code:

( Default.aspx)

<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true"CodeFile="Default.aspx.cs" Inherits="About" %>
<!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>Advance web
controls</title> </head>
<body>
<form id="form1"
runat="server"> <table
border="1">
<tr>
<td
>
<asp:Label ID="Label1" runat="server" Text="Relative URL
HyperLink"></asp:Label> </td>
<td>
<asp:Label ID="Label2" runat="server"
Text="Label"></asp:Label> </td>
<td>
<asp:Label ID="Label3" runat="server" Text="Select the file to
upload"></asp:Label> </td>
</tr
>
<tr>
<td>
<asp:LinkButton ID="LinkButton1"
runat="server">LinkButton</asp:LinkButton> </td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://www.google.com"
Target="_blank" ToolTip="Visit Google.com">Visit
Google.com</asp:HyperLink> <asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/Default2.aspx"
Target="_self">Click here to open
Default2.aspx</asp:HyperLink> </td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" /><asp:Button
ID="Button1" runat="server"
Text="Upload File" />
</td>
</tr>
</table>
</form>
</body>
</html>

5. Lab Exercises:

[Purpose of this exercise is to ASP.NET master pages allow you to create a consistent
layout for the pages in your application. A single master page defines the look and
feel and standard behavior that you want for all of the pages (or a group of pages) in
your application. You can then create individual content pages that contain the
content you want to display. When users request the content pages, they merge with
the master page to produce output that combines the layout of the master page with
the content from the content page.
Execution of program in two ways.
1. Press F5 button OR
2. Right click on ASP.NET page (for e.g.: Default.aspx) and Select “View Browser”
option and select any browser for execution.
3. Refresh the page to see the different images.

Exercise No5: ( 2 Hours) – 1 Practical


Lab Assignment 5: Master Page and Content page
Program: Demostration of master page and content page

Master Page
<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML


1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head runat="server" >
<title>Master page title</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><asp:contentplaceholder id="Main" runat="server" /></td>
<td><asp:contentplaceholder id="Footer" runat="server" /></td>
</tr>
</table>
</form>
</body>
</html>

Content Page

<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>


<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >


Footer content.
</asp:content>

6. Lab Exercises:

[Purpose of this exercise is to use Validation controls .You can use Visual Studio
.NET environment to type the program. Execution of program in two ways.
1. Press F5 button OR
2. Right click on ASP.NET page (for e.g.: Default.aspx) and Select “View Browser”
option and select any browser for execution.

Exercise No6: ( 2 Hours) – 1 Practical


Lab Assignment 6: Using Validation controls
Program:
Steps:

1. Design a Registration form Default.aspx page with fields Username, choose


password, confirm password, age, email id, city and a submit button.
2. Use:
a) RequiredFieldValidator - for Username, Choose password, Age, Email Id
fields.
b) CompareValidator - for Confirm password field.
c) RangeValidator - for Age field.
d) RegularExpressionValidator - for Email field.
e) CustomValidator - for City field.
3. Set the properties for:
a) RequiredFieldValidator - ControlToValidate, ErrorMessage.
b) CompareValidator - ControlToCompare, ControlToValidate, ErrorMessage.
c)RangeValidator - ControlToValidate, ErrorMessage, MaximumValue,
MinimumValue, Type.
d) RegularExpressionValidator - ControlToValidate, ErrorMessage
,ValidationExpression.
e) CustomValidator - ControlToValidate, ErrorMessage,
ClientValidationFunction.
4. Write a Client side script to use CustomValidator control (either JavaScript or
VBScript).
5. Display message “Successfully Submitted” after Clicking Submit button i.e after
successful validation of registration page.
( Default.aspx)
<%@ Page Language="c#" AutoEventWireup="false"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

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


Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration</title>
</head>
<body > <form id="form1"
runat="server"> <table>
<tr>
<td
>
UserName :
</td>
<td>
<asp:TextBox ID="txtUserName"
runat="server"></asp:TextBox> </td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtUserName"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td
> </tr>
<tr>
<td>
Choose Password
: </td>
<td>
<asp:TextBox ID="txtChoosePwd"
runat="server"></asp:TextBox> </td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtChoosePwd"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td> </tr>
<tr>
<td> Confirm Password :
</td>
<td>
<asp:TextBox ID="txtConfirmPwd" runat="server"></asp:TextBox> </td>
<td>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtChoosePwd" ControlToValidate="txtConfirmPwd"
ErrorMessage="Password Mismatch"></asp:CompareValidator>
</td> </tr>
<tr> <td>
Age: </td>
<td>
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox> </td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtAge" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtAge" ErrorMessage="18-40" MaximumValue="40"
MinimumValue="18" Type="Integer"></asp:RangeValidator>
</td> </tr>
<tr>
<td>
Email Id: </td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> </td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtEmail" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="Invalid email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</td>
</tr> <tr>
<td>City: </td> <td>
<asp:DropDownList ID="CityDropDown"
runat="server" CausesValidation="True">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Pune</asp:ListItem>
<asp:ListItem>Mumbai</asp:ListItem>
</asp:DropDownLis
t> </td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Please select the city" ClientValidationFunction="CityValidate"
ControlToValidate="CityDropDown"></asp:CustomValidator>
</td
> </tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Submit" Style="top: 211px; left:
125px; position: absolute; height: 26px; width: 61px" />
</form>
</body>
</html>
7. Lab Exercises:

[Purpose of this exercise is to use ADO.NET technology for showing records in Grid
view from Database .You can use Visual Studio .NET environment to type the
program. Execution of program in two ways.
1. Press F5 button OR
2. Right click on ASP.NET page (for e.g.: Default.aspx) and Select “View Browser”
option and select any browser for execution.

Exercise No7: ( 2 Hours) – 1 Practical


Lab Assignment 7: To show records in Gridview control
Program:
Steps:

1. Start a new website with Default.aspx web page.


2. Add Grid view control from tool box.
3. Steps for connecting to database:
8. Lab Exercises:

[Purpose of this exercise is to use ADO.NET technology for inserting records into
Database .You can use Visual Studio .NET environment to type the program. Execution of
program in two ways.
1. Press F5 button OR
2. Right click on ASP.NET page (for e.g.: Default.aspx) and Select “View Browser”
option and select any browser for execution.

Exercise No8: ( 2 Hours) – 1 Practical


Lab Assignment 8: To study the ADO.net and Stored procedure in asp.net.
Program:
Steps:

1. Start a new website with Default.aspx web page.


2. Add textboxes for Id, Name, Department and Button controls for Insert.
3. Steps for connecting to database:
a) Import the namespaces System.data and System.Data.SqlClient.
b) Establish the connection using connection object.
c) Open the connection.
d) Write SQL query in lCommand object.
e) Use Command methods for executing sql query.
f) Close the connection.
4. Use the validation controls for validation.

Default.aspx Stored Procedure

Default.aspx.cs
9. Lab Exercises:

[Purpose of this exercise is to use Dynamic Link Library.


1. Press F5 button OR
2. Right click on ASP.NET page (for e.g.: Default.aspx) and Select “View Browser”
option and select any browser for execution.

Exercise No9: ( 2 Hours) – 1 Practical


Lab Assignment 9: To study Dynamic link Library.
Program:
Steps:
1. Start a new website with Default.aspx web page.
2. Now Create class Library.
3. Write code in class library.
4. Add the reference of class library in Default.aspx.cs.
Exercise No10: ( 2 Hours) – 1 Practical
Lab Assignment 10:. To Study Crystal reports
Program: To show the reports

Steps:

a) 1. Add Typed DataSet to the ASP.Net Website.


b) Our next step would be to add a DataTable to the Type DataSet..
c) Adding Columns or fields to DataTable
d) Add Crystal Report to the ASP.Net Website
e) Once you press OK in the above dialog, the Report Wizard starts and you get
the following dialog where you need to choose the type of Database connection
for your Crystal Report. Since we are using DataSet we will choose the
Customers DataSet.
f) Next the Wizard will ask for the Columns or Fields from the Customer DataSet
you need to display on the Crystal Reports. You can choose either all or
specific fields as per you choice.
g) Write the code in Default.aspx

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral,


PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

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">
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</form>
</body>
</html>

Default.aspx.cs

using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;

protected void Page_Load(object sender, EventArgs e)


{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
Customers dsCustomers = GetData("select * from customers");
crystalReport.SetDataSource(dsCustomers);
CrystalReportViewer1.ReportSource = crystalReport;
}
private Customers GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;

sda.SelectCommand = cmd;
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}

4. Quiz on the subject:

Quiz should be conducted on tips in the laboratory, recent trends and subject knowledge of the
subject. The quiz questions should be formulated such that questions are normally are from the
scope outside of the books. However twisted questions and self formulated questions by the
faculty can be asked but correctness of it is necessarily to be thoroughly checked before the
conduction of the quiz.

5. Conduction of Viva-Voce Examinations:

Teacher should oral exams of the students with full preparation. Normally, the objective questions
with guess are to be avoided. To make it meaningful, the questions should be such that depth of
the students in the subject is tested Oral examinations are to be conducted in co-cordial
environment amongst the teachers taking the examination. Teachers taking such examinations
should not have ill thoughts about each other and courtesies should be offered to each other in
case of difference of opinion, which should be critically suppressed in front of the students.

6. Submission:
Document Standard:
A] Page Size A4 Size
B] Running text Justified text
C] Spacing 1 Line
D] Page Layout and Margins (Dimensions in Cms)
Normal Page Horizantal

2.0

2.5

2.0
2.5
2.0

0.7”
2.0

2.0
Desription Font Size Boldness Italics Underline Capitalize
College Name Arial 24 ----- ------ Yes ----------
Document Title Tahoma 22 ----- ------ --------- ----------
Document Subject Century Gothic 14 ----- ------ --------- Capital
Class Bookman old Slyle 12 ----- ------ --------- ----------
Document No Bookman old Slyle 10 ----- ------ --------- ----------
Copy write inf Bookman old Slyle 9 ----- ------ --------- ----------
Forward heading Bookman old Slyle 12 ----- ------ Yes Capital
Forward matter Bookman old Slyle 12 ----- ------ --------- ----------
Lab man Contents title Bookman old Slyle 12 ----- ------ Yes Capital
Index title Bookman old Slyle 12 Yes ------ Yes Capital
Index contents Bookman old Slyle 12 ----- ------ --------- ----------
Heading Tahoma 14 Yes Yes Yes ----------
Running Matter Comic Sans MS 10 ----- ------ --------- ----------

7. Evaluation and marking system:

Basic honesty in the evaluation and marking system is absolutely essential and in the process
impartial nature of the evaluator is required in the examination system to become popular
amongst the students. It is a wrong approach or concept to award the students by way of easy
marking to get cheap popularity among the students to which they do not deserve. It is a
primary responsibility of the teacher that right students who are really putting up lot of hard
work with right kind of intelligence are correctly awarded.

The marking patterns should be justifiable to the students without any ambiguity and teacher
should see that students are faced with unjust circumstances.

You might also like