2PGDCA4 (B) - Programming With ASP. Net: Unit-Ii 1. Overview of Dynamic Web Page
2PGDCA4 (B) - Programming With ASP. Net: Unit-Ii 1. Overview of Dynamic Web Page
Net
UNIT-II
The first version of ASP.Net deployed was 1.0. The most recent version of ASP.Net is
version 4.6. ASP.Net is designed to work with the HTTP protocol. This is the standard
protocol used across all web applications. ASP.Net applications can also be written in a
variety of .Net languages. These include C#, VB.Net, and J#.
High Performance
Supports Cross-Platform
This framework is the fastest and scalable as it offers a huge library which saves a lot of
time. This framework has been considered as the fastest framework as compared to other
frameworks.
Open Source
ASP.Net is based on the open-source feature, from time to time it gets updated by the
professionals. Hence, it is supported by an active and huge community. Huge support has
been provided to the ASP.net developers.
Secure Apps
With the ASP.net framework, developers can bring secure applications. The built-in
features help applications to prevent XSS and CDRF i.e cross-site scripting and cross-site
request forgery respectively. Inbuilt feature secure user database, and supports multi-
factor and external authentication with Twitter and Google.
Developers’ job is not easy, they have to face many challenges and develop the solution
as per the user’s demand. Regularly they have to face many challenges and they have to
fulfill the requirement of many other customers. Sometimes developers have the
requirement to develop the application which can be displayed only on desktop and it
should not be a server running IIS.
Hence, ASP.NET Framework offers various ways to develop the server free web apps.
3. Framework of ASP.NET
3.1 Component of ASP.Net Framework
4. Windows Forms:
The windows Forms application is used for creating window application in .NET. There
are wide controls and designing features available for Windows Forms.
The ASP.NET Framework contains more than 90 controls. These controls can be divided
into seven groups:
Standard Controls— Enable you to render standard form elements such as buttons,
input fields, and labels.
Validation Controls— Enable you to validate form data before you submit the data
to the server. For example, you can use a RequiredFieldValidator control to check
whether a user entered a value for a required input field.
Rich Controls—Enable you to render things such as calendars, file upload buttons,
rotating banner advertisements, and multistep wizards
Data Controls— Enable you to work with data such as database data. For example,
you can use these controls to submit new records to a database table or display a list
of database records.
Navigation Controls— Enable you to display standard navigation elements such as
menus, tree views, and bread crumb trails.
Login Controls—Enables you to display login, change password, and registration
forms.
HTML Controls— Enable you to convert any HTML tag into a server-side control.
5. Applications
When we hear .NET, the first idea that comes to your mind will probably be internet or
networked applications. Although this is absolutely true, there are many more types of
applications to create with .NET.
So here is a more or less full list of various types of application that we can develop on
.NET.
•ASP.Net Web applications are programs that used to run inside some web server to
fulfill the user requests over the http. ASP.NET Web applications can range from simple
Web sites that consist of HTML pages to advanced enterprise applications that run on
local and remote networks. These enterprise applications also provide components for
exchanging data using XML. This type includes dynamic and data driven browser based
applications. (Ex: Hotmail and Google).
•Web services are “web callable” functionality available via industry standards like
HTTP, XML and SOAP.
•Windows applications are form based standard Windows desktop applications for
common day to day tasks. (Ex: Microsoft word). Run only under Windows environment.
These applications consume the services provided by the Windows operating system.
•Windows services are long-running executable applications that run on the system as a
background process. These applications do not interfere with the working of the other
processes that run on the same computer. Windows services execute within separate
Windows sessions created specifically for each Windows service. These services do not
have a graphic user interface and are ideal for running on the server. Windows services
were earlier called NT services.
•Console applications are light weight programs run inside the command prompt (DOS)
window. They are commonly used for test applications.
•Mobile applications can run on multiple mobile devices, such as Pocket PCs, mobile
phones, or personal digital assistants. These applications provide ubiquitous access to
data from mobile devices. The .NET Framework automatically makes changes to these
applications to enable them to run on multiple browsers, depending on the mobile device.
•Class libraries are components that you create once and reuse a number of times in
multiple applications. Class libraries allow you to define several classes, along with their
methods and interfaces, in one file. These libraries compile to .dll files and facilitate rapid
development of new applications because of reusability of code. To access the
functionality of the classes in a class library from your application, you need to include a
reference to that library in your program.
All types of .NET applications use one or more .NET compliant languages for their
design and development. The .NET Framework includes various technologies, such as
ASP.NET, VB.NET, VC++.NET, and ADO.NET. You use ASP.NET to build Web
applications and services, VB.NET and VC++.NET to create Windows applications, and
ADO.NET for flexible access to databases.
6. Web Servers
A web server is a software program that serves web pages to web users (browsers).
A web server delivers requested web pages to users who enter the URL in a web browser.
Every computer on the internet that contains a web site must have a web server program.
The computer in which a web server program runs is also usually called a "web server".
So, the term "web server" is used to represent both the server program and the computer
in which the server program runs.
6.1 Characterizes of a Web Server
A web server computer is just like any other computer. The basic characteristics of web
servers are:
It is always connected to the internet so that clients can access the web pages
hosted by the web server.
It always has an application called "web server" running.
In short, a "web server" is a computer that is connected to the internet/intranet and has
software called "web server". The web server program will always be running in the
computer. When a user tries to access a website hosted by the web server, it is actually
the web server program that delivers the web page that the client asks for.
All web sites in the internet are hosted in web servers sitting in various parts of the world.
When I type in an URL such as http://www.ASP.NET and click on some link, I dropped
into this page. But what happens behind the scenes to bring you to this page and make
you read this line of text. So now, let's see what is actually happening behind the scenes.
The first you might do is, you type the http://www.asp.net/ in the address bar of your
browser and press your return key. We could break this URL into the following two
parts:
The browser breaks up the URL into these parts and then it tries to communicate
with the server looking up for the server name.
The server is identified through a unique IP address but the alias for the IP
address is maintained in the DNS Server or the Naming server.
The browser looks up these naming servers, identifies the IP address of the server
requested and gets the site and gets the HTML tags for the web page.
Finally it displays the HTML Content in the browser.
6.4 Where is my web server?
When you try to access a web site, you don't really need to know where the web server is
located. The web server may be located in another city or country, but all you need to do
is, type the URL of the web site you want to access in a web browser. The web browser
will send this information to the internet and find the web server. Once the web server is
located, it will request the specific web page from the web server program running in the
server. The Web server program will process your request and send the resulting web
page to your browser. It is the responsibility of your browser to format and display the
web page to you.
6.5 How many web servers are needed for a web site?
Typically, there is only one web server required for a web site. But large web sites like
Yahoo, Google, MSN and so on will have millions of visitors every minute. One
computer cannot process such huge numbers of requests. So, they will have hundreds of
servers deployed in various parts of the world so that can provide a faster response.
1. IIS
2. Apache
Internet Information Server (IIS) has it's own ASP.NET Process Engine to handle the
ASP.NET request. The way you configure an ASP.NET application depends on what
version of IIS the application is running on.
Internet Information Server (IIS) includes a set of programs for building and
administering Web applications, search engines, and support for writing Web-based
applications that access databases such as SQL Server. With IIS, you can make your
computer to work as a Web server and provides the functionality to develop and deploy
ASP.NET Web applications on the server. You can also set security for a particular
Website for specific Users and Computer in order to protect it from unauthorized access.
IIS helps organizations to increase Web sites and application availability while lowering
system administration and cost of deployment. IIS 7.5 supports HTTP, HTTPS, FTP,
FTPS, SMTP and NNTP.
8. Web Forms
ASP.NET is a development framework for building web pages and web sites with
HTML, CSS, JavaScript and server scripting. ASP.NET supports three different
development models: Web Pages, MVC (Model View Controller), and Web Forms.
Web Forms is one of the 3 programming models for creating ASP.NET web sites and
web applications. The other two programming models are Web Pages and MVC (Model,
View, and Controller). Web Forms is the oldest ASP.NET programming model, with
event driven web pages written as a combination of HTML, server controls, and server
code. Web Forms are compiled and executed on the server, which generates the HTML
that displays the web pages. Web Forms comes with hundreds of different web controls
and web components to build user-driven web sites with data access.
ASP.NET's Web Forms provide you with the ability to build Web-based GUI
applications. Web Forms include Web pages (also called an ASP.NET page or web
Forms page) and GUI components (sometimes called server controls) such as text boxes,
buttons, list boxes, data grids, and so on. ASP.NET provides the flexibility to add these
controls to an ASP.NET page at run-time as well as at design-time as well as at design-
time. VS.NET provides design-time features to develop applications in no time. You add
controls to a page by dragging controls from the toolbox to the page and then setting the
controls' properties and event. Web Forms also provides a method for using the code
behind directive to separate your controls from the code. In other worlds you can write
code in a separate file from the controls.
9. Web Forms Controls
There are some Web Forms Controls which is given below with Real Time Example:-
Label Control
TextBox control
Button control
Literal control
PlaceHolder control
HiddenField control
FileUpload control
Image control
ImageButton control
ImageMap control
The Label Control is basically used to display the Information(Text) on Web Forms.Any
end User can not Edit(change) the Label Information.
The TextBox control is used to input the Data(text).Any end user can easily enter the text
in this control.
The Button control is used to create an Event and send request to the web server.
It is similar to Label control but there are some differences and similarities which is given
below.
Literal and Label control both are used to display the text(information) on the web
form.
On Browser side Label control is converted to HTML 'Span' tag but Literal
control is not converted in any HTML tag.
We can provide formatting to the Label control but not to the Literal control.
If we want to show some HTML code and java script code the we used mainly
Literal control ,not Label control.Encoding Mode is used with Literal control
only.
Properties of Literal Control:-
It is known as container control in Asp. Net. It is mainly used to store the value of other
controls. You can Add controls to a Web Form by using the Controls.Add() Method.
It is used to display the value stored in the Hidden Field control in the Label control. It
stores the information in the form of Strings.
It is basically used to Upload the File on the server using SaveAs() method on the click
Event. When user browse a File and after browse click the Upload button then File is
automatically Upload on the Server.
Alternate Text:- It is used to display alternate text when the image is not present.
ImageAlign:-It is used to sets the alignment of image control on the web page.
ImageUrl:-It is used to sets the path to an image to display in the image control.
Font:-It is used to increase or decrease font of the image control text.
DescriptionUrl:-It is used to set the location to a detailed description for the
image.
It is used to display the image on Button instead of text. Properties of Image Button is
same as Button property.
Automatic state management, where values are retained across round trips to the
server
Access to object values without using request objects
Handling events for specific actions in server-side code
A simple approach for producing a dynamic Web page with complex rendering
and behavior
Using adaptive rendering to implement "write once render anywhere." Different
markup and layout are created to render anywhere for any type of device or
browser.
The following table contains the server-side controls for the Web Forms.
Data Grid Cancel Command, Edit Command, It used to create a grid that is used
Delete Command, Item Command, to show data. We can also perform
Selected Index Changed, Page Index paging, sorting, and formatting
Changed, Sort Command, Update very easily with this control.
Command, Item Created, Item Data
Bound
Data List Cancel Command, Edit Command, It is used to create data list that is
Delete Command, Item Command, non-tabular and used to show data.
Selected Index Changed, Update
Command, Item Created, Item Data
Bound
When client or user request a for a new page to the server then browser send request to
server to access new page then server response back to client through the browser using
html language and display HTML . as we discussed that client side control are html
control and always written using <input> tag to create html control. Client side control
are processed by browser and executed on browser and return back to browser i.e.
browser understand only html control. Generally HTML control are use to perform page
validation through java script (client side programming), normal calculation and
displaying text information etc where no need to perform task through server.
The following table contains the client-side controls for the Web Forms.
Controls Description
Name
Reset Resets all other HTML form elements on a form to a default value
Button
Submit Automatically POSTs the form data to the specified page listed in the Action
Button attribute in the FORM tag
File Field Places a text field and a Browse button on a form and allows the user to select
a file name from their local machine when the Browse button is clicked
Password An input area on an HTML form, although any characters typed into this field
Field are displayed as asterisks
Check Box Gives the user a check box that they can select or clear
Radio Used two or more to a form, and allows the user to choose one of the controls
Button
List Box Displays a list of items to the user. You can set the size from two or more to
specify how many items you wish show. If there are more items than will fit
within this limit, a scroll bar is automatically added to this control.
Dropdown Displays a list of items to the user, but only one item at a time will appear.
The user can click a down arrow from the side of this control and a list of
items will be displayed.
Horizontal Displays a horizontal line across the HTML page
Rule
Let's look at the other controls available for Web forms and see some of their common
properties.
In our example, we will create one form which will have the following functionality.
Let's look at each control in detail. Let's add them to build the form with the above-
mentioned functionality.
Step 1) The first step is to open the Forms Designer for the Demo web form. Once you
do this, you will be able to drag controls from the toolbox to the Web form.
Step 1) The first step is to drag the 'label' control on to the Web Form from the toolbox as
shown below.
Step 2) Once the label has been added, follow the following steps.
Once you make the above changes, you will see the following output
Output:-
You will see that the Name label appears on the Web Form.
12.2 Textbox
A text box is used for allowing a user to enter some text on the Web form application.
Let's see how we can implement this with an example shown below. We will add one
textbox to the form in which the user can enter his name.
Step 1) The first step is to drag the textbox control onto the Web Form from the toolbox
as shown below
Below is how this would look in the forms designer once the Textbox control is on the
form
Step 2) Once the Textbox has been added, you have to change the ID property.
Once you make the above changes, you see the following output.
Output:-
12.3 List box
A List box is used to showcase a list of items on the Web form. Let's see how we can
implement this with an example shown below. We will add a list box to the form to store
some city locations.
Step 1) The first step is to drag the list box control on to the Web Form from the toolbox
as shown below
Step 2) Once you drag the list box to the form, a separate side menu will appear. In this
menu choose the 'Edit Items' menu.
Step 3) You will now be presented with a dialog box in which you can add the list items
to the listbox.
Output:-
From the output, you can clearly see that the Listboxes was added to the form.
12.4 RadioButton
A Radio button is used to showcase a list of items out of which the user can choose one.
Let's see how we can implement this with an example shown below. We will add a radio
button for a male/female option.
Step 1) The first step is to drag the 'radiobutton' control onto the Web Form from the
toolbox. ( see image below). Make sure to add 2 radio buttons, one for the option of
'Male' and the other for 'Female.'
Step 2) Once the Radiobutton has been added, change the 'text' property.
Output:-
From the output, you can clearly see that the radio button was added to the form
12.5 Checkbox
A checkbox is used to provide a list of options in which the user can choose multiple
choices. Let's see how we can implement this with an example shown below. We will add
2 checkboxes to our Web forms. These checkboxes will provide an option to the user on
whether they want to learn C# or ASP.Net.
Step 1) The first step is to drag the checkbox control onto the Web Form from the
toolbox as shown below
Step 2) Once the Checkboxes have been added, change the checkbox id property to
'chkASP'.
Also, change the text property of the Checkbox control to 'C#'. Do the same for the other
Checkbox control and change it to 'ASP.Net'.
1. Change the ID property of the checkbox to 'chkASP'
2. Change the ID property of the checkbox to chkC
Once you make the above changes, you will see the following output
Output:-
From the output, you can clearly see that the Checkboxes was added to the form.
12.6 Button
A button is used to allow the user to click on a button which would then start the
processing of the form. Let's see how we can implement this with our current example as
shown below. We will add a simple button called 'Submit' button. This will be used to
submit all the information on the form.
Step 1) The first step is to drag the button control onto the Web Form from the toolbox as
shown below
Step 2) Once the button has been added, go to the properties window by clicking on the
button control. Change the text property of the button control to Submit. Also, change the
ID property of the button to 'btnSubmit'.
Once you make the above changes, you will see the following output
Output:-
From the output, you can clearly see that the button was added to the form.
12.7 Event Handler in ASP.Net
When working with a web form, you can add events to controls. An event is something
that happens when an action is performed. Probably the most common action is the
clicking of a button on a form.
In web forms, you can add code to the corresponding aspx.cs file. This code can be used
to perform certain actions when a button is pressed on the form. This is generally the
most common event in Web Forms. Let's see how we can achieve this.
We are going to make this simple. Just add an event to the button control to display the
name which was entered by the user. Let's follow the below steps to achieve this.
Step 1) First you have to double-click the Button on the Web Form. This will bring up
the event code for the button in Visual Studio.
The btnSubmit_Click event is automatically added by Visual Studio when you double
click the button in the web forms designer.
Step 2) Let's now add code to the submit event to display the name textbox value and the
location chosen by the user.
protected void btnSubmit_Click(object sender,EventArgs e)
{
Response.Write(txtName.Text + "</br>");
Response.Write(lstLocation.SelectedItem.Text + "</br>");
lblName.Visible = false;
txtName.Visible = false;
lstLocation.Visible = false;
chkC.Visible = false;
chkASP.Visible = false;
rdFemale.Visible = false;
btnSubmit.Visible = false;
}
Code Explanation:-
1. The above line of code does the simplest thing. It takes the value of the Name
textbox control and sends it to the client via the Response object. So if you want
to enter the string "Guru99" in the name text box, the value of txtName. A text
would be 'Guru99'.
2. The next line of code takes the selected value of the listbox via the property
'lstLocation.SelectedItem.text'. It then writes this value via the Response.Write
method back to the client.
3. Finally, we make all the controls on the form as invisible. If we don't do this, all
the controls plus our response values will be displayed together.
Normally, when a person enters all the information on the form such as the Name,
location, Gender, etc. The next page shown to the user should only have the
information which was not entered. The user does not want to see the Name,
Gender, location controls again. But ASP. Net does not know this, and hence, by
default, it will again show all the controls when the user clicks the Submit button.
Hence, we need to write code to ensure all the controls are hidden so that the user
just sees the desired output.
One you make the above changes, you will see the following output
Output:-
1. Give a name of Guru99(you can give your name also) in the name textbox
2. Choose a location in the listbox of Bangalore
3. Click on the Submit button
Once you do this, you will see 'Guru99' and the location 'Bangalore' is displayed on the
page.
References:
http://www.wideskills.com/aspnet/aspnet-introduction
https://www.c-sharpcorner.com/UploadFile/c8b86e/introduction-to-web-server/
http://net-informations.com/faq/asp/iis.htm
https://www.msdotnet.co.in/2013/06/web-forms-controls-in-
aspneti.html#.Xpn3BEAzbMw
https://www.javatpoint.com/asp-net-web-form-introduction
https://www.guru99.com/asp-net-controls.html