ASP.NET WEB FORMS

ASP.NET WEB FORMS WITH EXAMPLE

Introduction

The Web Forms classification comes under the ASP.NET web application framework.

 The Web Forms is one of the programming models that you can use to create interactive ASP.NET web applications.

The other models are as following:

•    ASP.NET MVC

•    ASP.NET Web Pages

•    ASP.NET Single Page Applications

What Is Web Form

  • A Web Form, or HTML form, is an online page that allows user input.
  • It is an interactive page, where users fill out particular fields.
  • Web forms are rendered in browsers using HTML and other web-oriented languages like CSS, javascript.

Processing of Web Form

  • Web Form Processing follows the Client-Server Architecture.
  • A client may be any machine or any device or any web browser.
  • The user requests information through a Web form.
  • A request sent to the server. The server finds the required information from the database.
  • Relevant information send to Client (Web Browser) in HTML format.

HELP TO OVERCOME THE LIMITATIONS OF CLASSIC ASP

Web application programming helps to overcome the limitations of programming traditional client-based applications.

1.    Improved web user interface

It will be challenging to design and develop a user interface using basic HTML controls when the page has dynamic content and user-interactive objects.

2.    Client and server

 The request send from your client browser has to travel across the network to execute some server-side code and returns the appropriate response in HTML form through the web browser.

3.    Stateless

  • When a request for information sends using web page, the information on web page discarded after the request is processed once.
  • If the same page requested by the user, then the entire process repeats.
  • Information of pages is not saved at the server.
  • Pages are stateless.

4.    Client capabilities

Browsers like Chrome, Mozilla, etc., have different capabilities, it is challenging to create an application that will run equally well on all type of browsers.

5.    Complications with scalability

Using the existing method of Web Application, Scalability not found in an application for the different client due to the lack of compatibility between the various components of the application.

The Web Forms addressed these challenges in the following ways:

•    Consistent object model

•    Event-driven programming model

•    State management

•    Browser-independent applications

•    .NET Framework common language runtime support

•    .NET Framework scalable server performance

FEATURES OF ASP.NET WEB FORMS

  • Client Script and Client Frameworks- ASP.NET Web Forms supports Client-Side scripting language like HTML, CSS, JavaScript, which enhances the server-based features.
  • Server Side Controls- When the web page requested server-side controls, the object on ASP.NET Web pages are rendered. Web server controls are similar to HTML elements, such as text boxes and buttons. Also, other controls like Calendar, Gridview, etc. are used to connect to data sources and display data.
  • Master Pages- Master page helps to create a consistent look and feel and standard behavior for other child pages.
  • Working with Data- ASP.NET provides different methods for storing, retrieving, and displaying data.
  • State Management- State management is a concept to use a value in various web pages and also in the overall application.
  • Routing- Web forms URL routing manages routing tables to maintain URLs.

Routing is used to define URLs that are semantically meaningful to users that can help with search engine optimization (SEO).

  • Security- ASP.NET Web Forms supports encryption and decryption for security on the network.
  • Debugging and Error Handling- Debugging and error handling is the feature within ASP.NET Web Forms that allows your applications to compile and execute effectively.
  • Deployment and Hosting- Visual Studio, ASP.NET, and IIS provide tools that help to deploy and hosting the Web Forms application.

Controls with their properties used in the Web Form

Following controls are used in ASP.NET Web Form:

  1. TextBox control
  2. Literal control
  3. Label Control
  4. Button control
  5. FileUpload control
  6. Image control
  7. ImageButton control
  8. ImageMap control
  9. PlaceHolder control
  10. HiddenField control

1. TextBox control

  • TextBox control is used to take input from the user.
  • Some properties of textbox control are Text, TextMode, ReadOnly,AutoPostBack etc .

Syntax:

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

2. Literal control

  • Literal control is used to show static data.
  • Some properties of Literal control are Text, Mode, etc.

Syntax:

<asp:Literal ID="Literal1" runat="server" Text="LiteralTest"></asp:Literal>

3. Label Control

  • Label control is used to show some information to the user.
  • Some properties of Label Control are Text, Font, ForeColor, BackColor, etc.

Syntax:

<asp:Label ID="lblMessage" EnableViewState="false" runat="server" Text="Label"></asp:Label>

4. Button control

  • Button control is used to fire an event and send a request to the Web Server.
  • Some properties of Button Control are Text, OnClientClick, Click, etc.

Syntax:

<asp:Button ID="Button1" runat="server" Text="Button" />

5. FileUpload control

  • FileUpload control is used to Upload the File on the Web Server.
  • Some properties of FileUpload Control are Visible, Tooltip, Height, Width, etc.

Syntax:

<asp:FileUpload ID="FileUpload1" runat="server" BackColor="Black" ForeColor="#FF6666" Visible="False" />

6. Image control

  • Image control is used to display the image on the web form.
  • Some properties of FileUpload Control are Alternate Text, ImageAlign, etc.

Syntax:

<asp:Image ID="Image1" runat="server" />

7. ImageButton control

  • ImageButton control is used to display the image on Button.ImageButton control that performs the same action as Button Control.
  • Some properties of ImageButton Control are AlternateText, Enabled, ImageUrl, etc.

Syntax:

<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" Width="52px" />

8. ImageMap control

  • ImageMap control provides different kind of Hotspots (Like RectangleHotSpot, CircleHotSpot, PolygonHotSpot, etc.).
  • These hotspots allow the user to navigate to other web pages on clicking ImageMap.
  • Some properties of ImageMap control are ImageUrl, Enabled, Target, etc.

9. PlaceHolder control

PlaceHolder control is used to add controls like labels, text boxes, images, etc. dynamically at run time.

Some properties of PlaceHolder control are Visible,BackColor,ForeColor etc.

Code for aspx page

  <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
 <asp:Button ID="btnPlaceHolder" runat="server" Text="Add Image Using PlaceHolder" OnClick="btnPlaceHolder_Click" /> 

Code for .cs page

protected void btnPlaceHolder_Click(object sender, EventArgs e)
         {
             Image img = new Image();
             img.ImageUrl = @"~/login.jpg";
             img.BorderWidth = 3;
             img.BorderColor = System.Drawing.Color.SaddleBrown;
             PlaceHolder1.Controls.Add(img);
             PlaceHolder1.Visible = true;
         } 

10. HiddenField control

  • The HiddenField control is used to store the value which is used in the background process of the web form and not shown to the user.
  • Some properties of HiddenField control are Value, EnableViewState, ViewStateMode, etc.

Code for aspx page

<asp:Button ID="btnSave" runat="server" Font-Bold="true" Text="Click Here To Save Value in HiddenField" OnClick="Button1_Click" />
 <asp:Button ID="btnShow" runat="server" Font-Bold="true" Text="Click Here To show Value in HiddenField" OnClick="Button2_Click" /> 

Code for .cs page

 protected void btnSave_Click(object sender, EventArgs e)
         {
             HiddenField1.Value = txtName.Text;
         }
 protected void btnShow_Click(object sender, EventArgs e)
         {
             txtPassword.Text = HiddenField1.Value;
             txtPassword.Enabled = false;
         } 
ASP.NET WEB FORMS WITH EXAMPLE 5