You are on page 1of 9

ASSIGNMENT - II

2 MARKS

1. WEB CONTROL:

Web controls are basically HTML elements wrapped under easy to use scripting tags of ASP+
and provide rich functionality in your FORMs or pages. Web controls range from simple text box to
advance girds and lists.

2. DATALIST CONTROL:

The ASP.NET DataList control is a light weight server side control that works as a container for data
items. It is used to display data into a list format to the web pages. It displays data from the data source.
The data source can be either a DataTable or a table from database.

3. TYPES OF VALIDATION CONTROL:

ASP.NET provides the following validation controls:

 RequiredFieldValidator.
 RangeValidator.
 CompareValidator.
 RegularExpressionValidator.
 CustomValidator.
 ValidationSummary.

4. NAVIGATION CONTROL:

Navigation Control is defined as a menu that can be stored in a file to make it easier to
maintain. This file is normally called web.Sitemap, and is stored in the root directory of the web. An
ASP.NET has three different types of Navigation control:

* Dynamic Menus

* TreeView

* Site Map path

5. DEFINING A FILE UPLOAD CONTROL:

ASP.NET FileUpload control allows us to upload files to a Web Server or storage in a Web
Form. To create a control, simply drop the FileUpload control from Toolbox to a Web page. The
following code adds the FileUpLoad control:

<asp:FileUpload id="FileUpLoad1" runat="server" />


5 MARKS

1. WEB CONTROL CLASSES:

Web control classes are defined in the System.Web.UI.WebControls namespace. They


follow a slightly more tangled object hierarchy than HTML server controls:

2. AUTO POSTBACK METHOD:

Autopostback is the mechanism, by which the page will be posted back to the server
automatically based on some events in the web controls. In some of the web controls, the
property called auto post back, which if set to true, will send the request to the server when
an event happens in the control

example:
Dropdown Box (Combo box) web control has the property autopostback.If we set the
property to true, when ever user selects a different value in the combo box, and event will
be fired in the server. i.e. a request will be send to the server.

HOW IT IS HAPPENING:

Whenever we set autopostback attribute to true in any of the controls, the .net framework
will automatically insert few code in to the HTML generated to implement this functionality.

These are the additional items that the framework will inject to the HTML source for
implementing autopostback event.

a. A Java script method with name __doPostBack (eventtarget, eventargument)


b. Two Hidden variables with name __EVENTTARGET and __EVENTARGUMENT
c. OnChange JavaScript event to the control
3. ASP.NET PAGE LIFE CYCLE:
The Page Life Cycle To understand how web control events work, you need
to have a solid understanding of the page life cycle. Consider what happens when a user
changes a control that has the AutoPostBack property set to true:

1. On the client side, the JavaScript __doPostBack function is invoked, and the page
is resubmitted to the server.

2. ASP.NET re-creates the Page object using the .aspx file.

3. ASP.NET retrieves state information from the hidden view state field and updates
the controls accordingly.

4. The Page.Load event is fired.

5. The appropriate change event is fired for the control.

6. The Page.PreRender event fires, and the page is rendered.

7. Finally, the Page.Unload event is fired.

8. The new page is sent to the client.

3. PROGRAM FOR GREETING CARD:

.aspx

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

CodeFile="GreetingCardMaker.aspx.cs" Inherits="GreetingCardMaker" %>

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

<head runat="server">

<title>Greeting Card Maker</title>

</head>

<body>

<form runat="server">

<div>

<!-- Here are the controls: -->

Choose a background color:<br />

<asp:DropDownList ID="lstBackColor" runat="server" Width="194px"

Height="22px"/><br /><br />

Choose a font:<br />

<asp:DropDownList ID="lstFontName" runat="server" Width="194px"


Height="22px" /><br /><br />

Specify a numeric font size:<br />

<asp:TextBox ID="txtFontSize" runat="server" /><br /><br />

Choose a border style:<br />

<asp:RadioButtonList ID="lstBorder" runat="server" Width="177px"

Height="59px" /><br /><br />

<asp:CheckBox ID="chkPicture" runat="server"

Text="Add the Default Picture"></asp:CheckBox><br /><br />

Enter the greeting text below:<br />

<asp:TextBox ID="txtGreeting" runat="server" Width="240px" Height="85px"

TextMode="MultiLine" /><br /><br />

<asp:Button ID="cmdUpdate" OnClick="cmdUpdate_Click"

runat="server" Width="71px" Height="24px" Text="Update" />

</div>

<!-- Here is the card: -->

<asp:Panel ID="pnlCard" runat="server"

Width="339px" Height="481px" HorizontalAlign="Center"

style="POSITION: absolute; TOP: 16px; LEFT: 313px;">

<br />&nbsp;

<asp:Label ID="lblGreeting" runat="server" Width="256px"

Height="150px" /><br /><br /><br />

<asp:Image ID="imgDefault" runat="server" Width="212px"

Height="160px" />

</asp:Panel>

</form>

</body>

</html>

.aspx.cs

public partial class GreetingCardMaker : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)

if (!this.IsPostBack)

lstBackColor.Items.Add("White");

lstBackColor.Items.Add("Red");

lstBackColor.Items.Add("Green");

lstBackColor.Items.Add("Blue");

lstBackColor.Items.Add("Yellow");

lstFontName.Items.Add("Times New Roman");

lstFontName.Items.Add("Arial");

lstFontName.Items.Add("Verdana");

lstFontName.Items.Add("Tahoma");

ListItem item = new ListItem();

item.Text = BorderStyle.None.ToString();

item.Value = ((int)BorderStyle.None).ToString();

lstBorder.Items.Add(item);

item = new ListItem();

item.Text = BorderStyle.Double.ToString();

item.Value = ((int)BorderStyle.Double).ToString();

lstBorder.Items.Add(item);

item = new ListItem();

item.Text = BorderStyle.Solid.ToString();

item.Value = ((int)BorderStyle.Solid).ToString();

lstBorder.Items.Add(item);

lstBorder.SelectedIndex = 0;

imgDefault.ImageUrl = "defaultpic.png";

protected void cmdUpdate_Click(object sender, EventArgs e)

{
pnlCard.BackColor = Color.FromName(lstBackColor.SelectedItem.Text);

lblGreeting.Font.Name = lstFontName.SelectedItem.Text;

if (Int32.Parse(txtFontSize.Text) > 0)

lblGreeting.Font.Size =

FontUnit.Point(Int32.Parse(txtFontSize.Text));

int borderValue = Int32.Parse(lstBorder.SelectedItem.Value);

pnlCard.BorderStyle = (BorderStyle)borderValue;

if (chkPicture.Checked)

imgDefault.Visible = true;

else

imgDefault.Visible = false;

lblGreeting.Text = txtGreeting.Text;

5. COLOR, FONT AND LIST CONTROL IN WEB CONTROL:

Color:
The Color property refers to a Color object from the System.Drawing namespace. You
can create color objects in several ways:
Using an ARGB (alpha, red, green, blue) color value:
You specify each value as an integer from 0 to 255. The alpha component
represents the transparency of a color, and usually you'll use 255 to make the color
completely opaque.
Using a predefined .NET color name:
You choose the correspondingly named read-only property from the Color
structure. These properties include the 140 HTML color names.
Using an HTML color name:
You specify this value as a string using the ColorTranslator class.
Fonts:

The Font property actually references a full FontInfo object, which is defined in the
System.Web.UI.WebControls namespace. Every FontInfo object has several properties that
define its name, size.

FontInfo Properties:

Property Description
Name A string indicating the font name (such as Verdana)
Names Names An array of strings with font names, in the order of
preference. The browser will use the first matching font that's
installed on the user's computer.
Size The size of the font as a FontUnit object. This can represent an
absolute or relative size
Bold, Italic, Strikeout, Boolean properties that apply the given style attribute
Underline, and
Overline

Lists controls:
The list controls include the ListBox, DropDownList, CheckBoxList, RadioButtonList,
and BulletedList. They all work in essentially the same way but are rendered differently in the
browser. The ListBox, for example, is a rectangular list that displays several entries, while the
DropDownList shows only the selected item. The CheckBoxList and RadioButtonList are
similar to the ListBox, but every item is rendered as a check box or option button,
respectively. Finally, the BulletedList is the odd one out—it's the only list control that isn't
selectable.

10 MARKS

1. RICH CONTROLS:

Rich controls are web controls that model complex user interface elements. Although no
strict definition exists for what is and what isn't a rich control, the term commonly describes
a web control that has an object model that's distinctly separate from the HTML it generates.
A typical rich control can be programmed as a single object (and added to a web page with a
single control tag) but renders itself using a complex sequence of HTML elements. Rich
controls can also react to user actions (such as a mouse click on a specific region of the
control) and raise more meaningful events that your code can respond to on the web server.
In other words, rich controls give you a way to create advanced user interfaces in your web
pages without writing lines of convoluted HTML.

2. VALIDATION CONTROLS:
ASP.NET provides five validator controls. Four are targeted at specific types of validation,
while the fifth allows you to apply custom validation routines. You'll also see a
ValidationSummary control in the Toolbox, which gives you another option for showing a
list of validation error messages in one place.
RequiredFieldValidator:
Validation succeeds as long as the input control doesn't contain an empty string.
RangeValidator:
Validation succeeds if the input control contains a value within a specific numeric,
alphabetic, or date range.
CompareValidator:
Validation succeeds if the input control contains a value that matches the value in
another input control, or a fixed value that you specify.
RegularExpressionValidator:
Validation succeeds if the value in an input control matches a specified regular
expression.
CustomValidator:
Validation is performed by a user-defined function.
ValidationSummary:
It gives you another option for showing a list of validation error messages in one
place.

3. WEB FORM 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

Label 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.

TextBox control:
The TextBox control is used to input the Data(text).Any end user can easily enter the
text in this control.

Button control:
The Button control is used to create an Event and send request to the web server.
Literal control:
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.

PlaceHolder 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.

HiddenField control:

It is used to display the value stored in the HiddenField control in the Label control.It
stores the information in the form of Strings.

FileUpload control:
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.

Image control:
It is used to display an image on a web page.

ImageButton control:
It is used to display the image on Button instead of text.Properties of ImageButton is
same as Button property.

ImageMap control:
It is used to provide various links(hotspots) to navigate to other web page,depending
on the place where the user clicks.

You might also like