A) HTML Server Controls: System - Web.Ui - Webcontrols Namespace
A) HTML Server Controls: System - Web.Ui - Webcontrols Namespace
namespace.
b) Web Server
Controls/Web
Controls/ASP.NET
Web
Form
Controls)
These are the new generations controls developed by Microsoft.
In the HTML or .aspx file, these are typically referenced with an
the
System.Web.UI.WebControls namespace.
c) Validation Controls
This set of controls provides features for automatically checking the
namespace.
d) Custom Controls
You can develop your own server controls by extending an existing
as .ascx files.
The Web Custom Controls require in-depth knowledge of Object
Oriented
Programming
and
the
Common
Language
Runtime
In an IIS environment, the ASP and ASP.NET can run side by side. If you
install ASP.NET, your existing ASP applications will continue running.
The IIS uses the ASP Engine to process the .asp files, whereas it uses the
ASP.NET Engine to process the .aspx files. Session states and
application states are not shared between ASP and ASP.NET pages.
Collecting Data Using HTML Forms
HTML uses the Hypertext Transfer Protocol (HTTP) to transmit Web
pages.
When you enter a URL of a page in your browser,
The browser sends an HTTP message to the server, requesting the
desired page.This message is typically known as the Request
message.
If the desired page has a *.html or *.htm extension, the Web server
simply retrieves the page from the servers disk and sends it back to
your computer (client) via a new HTTP message, known as the
Response message.
It is your browser that interprets the mark-up codes in the Response
If it is Get, the browser sends the data in the header section of the
HTTP message.
If it is Post, the data are sent in the body section.
The Action parameter can be used to request a specified html or other
documents like .asp or .aspx files.
<form
name=
"myForm"
Action="Sample1.html"
Method="Get">
will take place on every request. That is why, the list box will keep on
growing in size.
In order to solve the above two problems use the following code listing
Sub Page_Load(ByVal source As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
lstFlower.Items.Add("Tulip")
lstFlower.Items.Add("Gaye")
lstFlower.Items.Add("Hailu")
lstFlower.SelectedIndex = 0
End If
End Sub
ID="lstFlower"
Rows="3"
runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="Show_selection"></asp:ListBox>
Microsoft
has
outlined
the
following
browser-compliant HTML.
It can be programmed in any CLR-supported language.
It supports WYSIWYG editing tools and development tools such as
VS.NET.
It supports a rich set of controls that enables you to encapsulate page
Page Directives
Page directives are used to set various attributes about a page.The ASP
Engine and the compiler follow these directives to prepare a page.
There are many kinds of directives.The most frequently ones are the
following: @ Page, @ Import,@ Implements, @ Register,@ OutputCache
and @ Assembly directives.
These directives can be placed anywhere in a page, however, these are
typically placed at the top.
Page Directives and Their Functions
a) @ Page
We may use this directive to declare many page-related attributes
about a particular page. For example, we use this directive to declare
used
ones
are
these:
EnableSessionState,
AutoEventWireup,
ErrorPage,
Debug,
Buffer,
Trace,
Register
tagprefix
Src=TimeUserControl.ascx%>.
e) @ Assembly
=utoledo
tagname=Time
f) @ Implements
This directive enables us to implement an interface in our page. In the
following example, we are implementing the IpostBackEventHandler
interface in one of our user controls:
<%@
Implements
Interface=System.Web.UI
.IPostBackEventHandler %>.
Code-Behind versus In-Page Coding
Placing a certain amount of VB code inside .aspx file is called In-Page
Coding/Inline code.
All ASP applications had to be developed using in-page coding because
that was the only way to develop an ASP page.
Intermixed HTML and scripting codes in a large page become cryptic
and difficult to read and maintain. Fortunately,ASP.NET provides a way
out of this problem.We may develop the html code in a file with an .aspx
extension, and then we may write the necessary code in a separate C# or
VB code file. This practice is known as Code-Behind.
When we develop an ASP.NET application using VS.NET, we are
automatically forced to use Code-Behind.
Obviously, the .aspx file has to be somehow linked to the class file.We
may link the .aspx file with the code file in one of two ways:
1) Develop the class file and save it without compilation in the same
directory of the .aspx file, or
a. You do not need to compile the VB or C# class/source file. Just save
the source file and the .aspx file in the same virtual directory.
b. You will need to enter the following Page Declarative statement at the
top of your .aspx file.
<%@
page
language="VB"
src="vbCb.vb"
inherits="myVbCodeBehind.vbCb" %>
2) Compile the class file and save the .dll file in the bin subdirectory of
our virtual directory.
Using HTML Server Controls
Conventional HTML elements are not programmable at the server
side.Their values do not persist in postbacks.
HtmlInputCheckBox,
HtmlInputImage,
HtmlInputText
2) HTML Container controls
HtmlAnchor, HtmlButton,
HtmlForm,
HtmlInputFile,
HtmlInputRadioButton,
HtmlSelect,
HtmlTable,
and properties of the <a> element and display hyperlinks from a data
source.
The href attribute contains the URL of the page to be linked to.
Using the HtmlTable Control
We may define rows using <tr> tags. Table cells are defined using <td>
tags.This control is a container control, and so we can embed other
controls in its cells.
It has the following attributes:
<table runat="server" id="programmaticID" align=left|center|right
bgcolor="bgcolor"
border = "borderwidthinpixels" bordercolor="bordercolor"
cellpadding = "spacingwithincellsinpixels"
Cellspacing = "spacingbetweencellsinpixels" height="tableheight"
rows="collectionofrows" width="tablewidth" >
</table>
has
included
plethora
of
Web
controls
in
the
System.Web.UI.WebControls namespace.
These controls can be divided into three major categories:
a) Basic Web Controls These Web controls are similar to HTML server
controls but have additional features. These controls have a richer
and more consistent object model.
b) Validation Controls These controls have been developed exclusively
for input validation.
c) Databound ListControls These belong to the new generation of
controls that provide additional power and development speed. These
are also typically referred to as Templated Web Controls.
All Web controls are derived from the generic class named WebControl.
Basic Web Controls
Label
A Label is used to display text. If we want to display static text, we do
not need a Label server control; we should instead use HTML. We
should use a Label server control only if we need to change its
properties via server code.
TextBox
A TextBox control enables the user to enter text. By default, the
TextMode property is SingleLine, but it can also be set to Multiline or
Password. In case of Multiline text box, the Rows property determines
the height. If its AutoPostBack property is set to True, it generates a
PostBack on its Text_Changed() event.
Button
Button controls can be placed inside other container controls, such as
DataList, DataGrid and Repeater.
LinkButton
The LinkButton renders a hyperlink in the page.
ImageButton
The ImageButton displays an image that responds to mouse clicks. We
can also use it as an image map. Thus, we may pinpoint where in the
graphic the user has clicked.
CheckBox
It enables the user to input Boolean data: true or false, yes or no. Its
Checked property can also be bound to a data field of a data source. Its
CheckedChanged() event can be used for AutoPostBack.
CheckBoxList / DropDownList / ListBox / RadioButtonList
These controls are derived from the ListControl abstract class.
All three types of buttons (Button, LinkButton and Image button) cause
PostBacks when the user clicks them.
HyperLink
It displays a link to another page. It is typically displayed as text
specified in its Text property. It can also be displayed as an image
specified in the ImageUrl property. If both the Text and ImageUrl
properties are set, the ImageUrl property is displayed. If the image
does not exist, then the text in the Text property is shown. Internet
Explorer uses the Text property to display ToolTip.
Image
We may use the Image control to display an image on the Web page.
The ImageUrl property specifies the path to the displayed image.
When the image does not exist, we can specify the text to display in
place of the image by setting the AlternateText property. The Image
control only displays an image. If we need to capture mouse clicks on
the image, we should instead use the ImageButton control.
Panel
This can be used as a container of other controls. This control is
rendered as an HTML <div> element.
RadioButton
It creates an individual radio button on the page. We can group them
to present mutually exclusive choices.
Table
It enables us an HTML table. A table can be built at design time with
static content, but the Table control is often built programmatically
with dynamic contents. Programmatic additions or modifications to a
table row or cell do not persist on PostBack. Changes to table rows or
expression (pattern).
CompareValidator - Checks if the value is acceptable compared to a
specified range.
CustomValidator - Allows you to develop custom validation.
Note
You can get more regular expression from
www.microsoft.com/mind/defaulttop.asp?
page=/mind/1098/jscript/jscript.htm&nav=/mind/1098/inthisissuecolumn
s1098.htm.
The CompareValidator Control
The CompareValidator control compares an input to a specified value or
to the value of another control.You can also use it to check if the input is
of any particular data type.
If we have a textbox named txtR and in this textbox, the user is suppose
to enter a value its data-type to be
specify:
Equal,
NotEqual,
GreaterThan,
LessThan,
France.
The date of birth must be between 1/1/1940 and 1/12/1985.
Hire date must be after the date of birth and before 6/15/2001.
The user should enter the password twice, and both entries must be
identical.
<asp:RangeValidator id="ranvDateHired" runat="server"
type="Date" display="dynamic"
controlToValidate="txtDateHired" errorMessage="Hire date
must be before 6/1/2001" minimumValue="1/1/1900"
maximumValue="6/15/2001" >
</asp:RangeValidator>
<asp:CompareValidator id="comvConfirmPassword" runat="server"
display="static" controlToValidate="txtConfirmPassword"
controlToCompare="txtPassword" errorMessage="Both
passwords must be same" type="String" operator="Equal">
</asp:CompareValidator>
layout (required).
AlternatingItemTemplate Defines the layout of the zero-based odd
myConn.Close()
End Sub
</script>
<asp:DataGrid runat="server" id="DataGrid1"
AutoGenerateColumns="false" Width="75%" BackColor="White"
BorderWidth="1px" BorderStyle="Solid" CellPadding="2"
CellSpacing="0" BorderColor="Salmon" Font-Name="Verdana" FontSize="8pt" AllowSorting="true" OnSortCommand ="sortGrid">
<HeaderStyle Font-Size="8" Font-Names="Arial" Font-Bold="True"
BackColor="Yellow" HorizontalAlign="center">
</HeaderStyle>
<Columns>
<asp:BoundColumn HeaderText="Product ID" DataField="ProductId"
>
<ItemStyle HorizontalAlign="Right"/>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Unit Price" DataField="price"
DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="Right"/>
</asp:BoundColumn>
<asp:BoundColumn
HeaderText="Description"
DataField="ProductName">
<ItemStyle Width="130"/>
</asp:BoundColumn>
</Columns>
<AlternatingItemStyle BackColor="Beige"/>
</asp:DataGrid>
</center></body></html>