Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
90 views

Unit-4 - ASP - Net and Web Development - Part-1

Uploaded by

msself02
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Unit-4 - ASP - Net and Web Development - Part-1

Uploaded by

msself02
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 116

UNIT – 4

ASP.Net and Web Development


PART - 1_Introduction to ASP.NET
Outline
 Web Terms
 Essential Part of website
 Introduction to ASP.NET
 Advantages of ASP.NET
 Understanding ASP.NET Control
 Server Control
 Validation Control
 Rich Server Control
 Login Control
Web Terms
1. Web Application :
• In software engineering, a web application is an application that is accesses
via a web browser over a network such as the Internet or an intranet.
• The terms may also means a computer software application that is hosted
in a browser-controlled environment or coded in a browser-supported
language such as HTML.

2. Website :
• Website is nothing but a collection of Web Pages.
• Web site is a collection of Web files on a particular subject that includes a
beginning file called a home page.
• www.yahoo.com
• We can say above syntax is URL of the website which contains Web Pages.
Web Terms
3. Webpage:
• Files that travel across the largest network in the world, the Internet, and
carry information from a Server to Client that requested them are called
web pages.
• Means the pages stored on the server.
• The WebPages are created using HTML syntax.
• WebPages can be static or dynamic.

4. Server and Client :


• To access information stored in the form of web pages, users (Client) must
connect to a Web Server.
• The machine where the Web site actually resides is called a Web
server.
• Web server stored web documents.
Web Terms
• The web pages and related resources are stored into the central computer
and these files to be read over TCP/IP is called web server.
• The server computer runs special software called web server that do :
– Website management
– Receive Client Requests and Respond to a client’s request by providing
the pages.
• When we send a request for a Web page by entering a Web site address,
this request is sent to a Web Server. The Web server then sends the Web
page to your browser.
• A very large website may be spread over a number of servers in different
geographic locations.
• Clients have user interface but access data on a remote server.
• IIS , Wamp , Zamp , Apache are famous Web server.
Web Terms
5. Web Browser :
• Through the Web Browser we can view the WebPages.
• Web Browser is simply software, which sends request to a web server and
accepts a response to that request from the web server.
• To access web pages, the user must connect to the web server. Once the use
connected, a web browser will display the requested page. The Application
or software that offer the facility to read information stored in web pages
are called web client or web browser.
• Internet Explorer , Opera , Google Chrome , Mozilla , NetScape navigator
etc..
Essential Part of Website
1. HTML :
• It’s nothing but a designing or layout language.
• HTML stands for Hyper Text Markup Language.
• HTML is not a programming language, it is a markup language.
• Browser can understand only one language that one is HTML.
• We can create static pages with extension either .HTML or .HTM.
• The HTML contains TAGS and attributes of that tags.
• With the help of HTML language we can develop static pages.
Essential Part of Website
2. CSS :
• A cascading style sheet contains style rules that are applied to elements in a
Web page.
• CSS is a style sheet used to describe the presentation of a document written
in a markup language.
• CSS can be used to determine an element’s size, color, position and many
other feature.
• It’s a separation of document content from document presentation.
• Instead of assigning attributes to each element on your page individually,
you can create a general rule that applies attributes whenever a Web
browser encounters an instance of an element or an element that is
assigned to a certain style class.
Essential Part of Website
3. Client Side Scripting :
• With Client-side Scripting, the scripts on the page are processed by the
individual web browser that requests the page.
• With Server-side Scripting, on the other hand, all scripts are processed on
the server before the requested page is ever sent to the browser.
• The biggest limitation of HTML is that it is static.
• Client side coding is interpreted by the browser and run on the client.
• Do not have access to server resources.
• We have two options for client side coding JavaScript or VbScript.
• Client-side scripting executes in the browser after the page is loaded.
• Example :
• Client side validation, Image rotation, Where server side data not required.
Essential Part of Website
4. Server Side Scripting :
• PHP, JSP, ASP.NET etc. technologies are used for server side coding or
server side scripting.

5. Database :
• Database is used when we work with dynamic contents.
• Login, Registration, Message etc..
• MySQL, SQL Server, Oracle are famous Database software.
Introduction of ASP.NET
• ASP.NET is not ASP.
• ASP stands for Active Server Page.
• ASP.NET is the next generation ASP, but it’s not an upgraded version of
ASP.
• Like ASP, ASP.NET is a server-side technology.
• ASP.NET is an entirely new technology for server-side scripting. It was
written from the ground up and is not backward compatible with classical
ASP.
• ASP.NET is the major part of the Microsoft’s .NET Framework.
• ASP.NET is a server side scripting technology that enables scripts to be
executed by an Internet server.
• ASP.NET provides services to allow the creation, deployment and
execution of Web Application and Web Services.
• ASP.NET is a Microsoft Technology.
Introduction of ASP.NET
• ASP.NET is a programming framework built on the common language
runtime that can be used on a server to build powerful Web Application.
• ASP.NET is a program that runs inside IIS.
• IIS (Internet Information Services) is Microsoft’s Internet server.
• IIS comes as a free component with Windows servers.
• Web Applications are built using Web Forms.
• Web Forms are designed to make building web-based application as easy
as building Visual Basic applications.
Advantages of ASP.NET
1. Separation of Code from HTML
• To make a clean sweep, with ASP.NET you have the ability to completely
separate layout and business logic.
• This makes it much easier for teams of programmers and designers to
collaborate efficiently.

2. Support for compiled language


• Developer can use C#.NET and access features such as strong typing and
object-oriented programming.
• Using compiled language also means that ASP.NET pages do not suffer the
performance penalties associated with interpreted code.
Advantages of ASP.NET
3. Use service provided by the .NET Framework
• The .NET Framework provides class libraries that can be used by your
applications.
• Some of the key classes help you with input/output, access to operating
system services, data access, or even debugging. We will go into more
detail on some of them in this module.

4. Completely Object Oriented Support


• It supports completely object oriented support which includes an event
driven architecture.
Advantages of ASP.NET
5. Graphical Development Environment
• Visual Studio .NET provides a very rich development environment for
Web developers. You can drag and drop controls and set properties.

6. State management
• To refer to the problems mentioned before, ASP.NET provides solutions
for session and application state management.
• State information can, for example, be kept in memory or stored in a
database.

7. Update files while the server is running


• Components of your application can be updated while the server is online
and clients are connected.
Advantages of ASP.NET
8. XML-Based Configuration Files
• Configuration settings in ASP.NET are stored in XML files that you can
easily read and edit.
• You can also easily copy these to another server, along with the other files
that comprise your application.

9. Security
• With built in Windows authentication and per-application configuration,
you can be assured that your applications are secure.
Understanding ASP.NET Controls
• An ASP.NET control is a .NET class that executes on the server and
renders certain content to the browser.
1. Standard Control
2. Validation Control
3. Rich Control
4. Data Control
5. Navigation Control
6. Login Control
7. Webpart Control
8. HTML Control
Understanding ASP.NET Controls
1. Standard Controls or Web server Controls :
• Render Standard form elements such as buttons, labels, etc.
• Controls with more built-in features.
• They are Server side objects.
• They are programmable objects that act as User Interfaces (UI) elements
on a web page.
• Syntax :
<asp:ButtonID=“btnAns” runat=“server” Text=“Ans”/>

2. Validation Controls :
• Attach a validation control to an input control to test the data the user
enters into it.
• It is used to test user input.
Understanding ASP.NET Controls
3. Rich Controls :
• They enable you to render things such as file upload buttons, ad rotators,
calendar etc.

4. Data Controls :
• They enable you to work with data such as database data.
• They display data from database.
• We connect and display with data with database or wizard.

5. Login Controls :
• They enable you to display login, change password and registration forms.
Understanding ASP.NET Controls
6. Navigation Controls :
• These controls enable to you to display navigation elements such as menu,
sitemap and tree view.

7. Web part Controls :


• They enable you to personalize portal applications.

8. HTML Controls :
• HTML controls are used to work with the client side programming.
• We can convert HTML controls into Server control also.
• Syntax :
<input id=“btnClear” type=“button” value=“Click me” />
Understanding ASP.NET Controls
<head runat = “server”>
<title>Untitled Page</title>
<script language=“javascript” type=“text/javascript”>
<!- -
function Button1_onclick()
{
alert(form1.Text1.value);
}
-- >
</script>
</head>
<body id = “txtNo”>
<form id = “form1” runat = “server”>
Understanding ASP.NET Controls
<div>

<input id = “Text1” type = “text” />

<input id = “Button1” type = “button” value=“button” language=“javascript”


onclick=“returnButton1_onclick()” />

</div>
</form>
</body>
<html>
ASP.NET Server Controls
1. Button Control
• Button control is the control which we click and release to perform some
action.
• It displays a push button control on the web page.
• By default, buttons submit the page to the server and cause it to be
processed along with any pending events.

• Events :

Event Description
Click Occurs when we click on Button.
ASP.NET Server Controls
• Property :
Property Description
Causes Validation By default, a page is validated when a
Button control is clicked.
OnClientClick The name of the function to be executed
when the button is clicked.
PostbackUrl The URL of the page to post to from the
current page when the Button control is
clicked.
Text The text on the button.
Validation Group The group of controls for which the
Button control causes validation when it
posts back to the server.
ASP.NET Server Controls
• HTML View :
<asp:Button ID=“btnAns” runat = “server” Text=“Click me” onclick =
“btnAns_Click” />

• Coding View :
protected void btnAns_Click(object sender , EventArgs e)
{
Response.Write(“<h1>Hi I am ABC. </h1>”);
}
ASP.NET Server Controls
2. Label Control
• It enables us to display the static text on the web page.
• We can use the text property of the label control to display text on the web
page that be specified at the same time of designing.
• User cannot edit the text of label control at runtime.
• When we want to display the answer, tag, etc that time we will use it.
• We can also make Label controls child controls of other controls, such as
using them in Web server control templates.

• Property :
Text
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td>
<asp:Label ID=“lblNo” runat=“server” Text=“Enter no” BackColor=“Red”
BorderStyle=“Dotted” Font-Bold=“true” Font-Size=“X-Large”
ForeColor=“White”>
</asp:Label>
</td>
<td>
<asp:TextBox ID=“txtNo” runat=“server”>
</asp:TextBox>
</td>
</tr>
ASP.NET Server Controls
<tr>
<th colspan=“2”>
<asp:Button ID=“btnAns” runat=“server” Text=“Answer” onclick=“btnAns”>
</asp:Label>
</th>
</tr>
<tr>
<td>
<asp:Label ID=“Label1” runat=“server” Text=“Ans” BackColor=“Red”
BorderStyle=“Dotted” Font-Bold=“true” Font-Size=“X-Large”
ForeColor=“White”>
</asp:Label>
</td>
ASP.NET Server Controls
<td>
<asp:Label ID=“lblAns” runat=“server” Text=“Ans” BackColor=“Red”
BorderStyle=“Dotted” Font-Bold=“true” Font-Size=“X-Large”
ForeColor=“White”>
</asp:Label>
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void btnAns_Click(object sender , EventArgs e)


{
int no;
no = Convert.ToInt16(txtNo.Text);
if (no % 2 == 0)
{
lblAns.Text = “no is Even”;
}
else
{
lblAns.Text = “no is Odd”;
}
}
ASP.NET Server Controls
3. TextBox Control
• It appears like a box and allows the user to enter some text.
• The Textbox control provides a way for users to type information into an
ASP.NET web page including text, numbers and dates.

• Events :

Event Description
TextChanged Occurs when a user changes the text in
the TextBox.
ASP.NET Server Controls
• Property :
Property Description
AutoPostBack Value signaling whether the
AutoPostback feature is enabled for the
Control.
MaxLength The maximum number of characters
allowed the field.
ReadOnly Boolean value signaling whether control
may be edited y user or just read only.
Text The text contained within the field.
TextMode • Default mode is single line
• Multiline mode allows multiple line
entry.
Wrap • Boolean value signaling whether text
wraps within the field.
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td colspan=“2”> Fill your personal Information
<hr/>
</td>
</tr>
<tr>
<td>Name</td>
<td>
<asp:TextBox ID=“txtName” runat=“server” TextMode=“SingleLine”>
</asp:TextBox>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td>Address</td>
<td>
<asp:TextBox ID=“txtAddress” runat=“server” TextMode=“MultiLine”>
</asp:TextBox>
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox ID=“txtPwd” runat=“server” TextMode=“Password”>
</asp:TextBox>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td>&nbsp;</td>
<td>
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit” />
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void btnSubmit_Click(object sender , EventArgs e)


{
string str = null;
str = “Your Name is ” + txtName.Text;
str += “<br>Address is ” + txtAddress.Text;
str += “<br>Password is ” + txtPwd.Text;
Response.Write(str);
}
ASP.NET Server Controls
4. RadioButton Control
• It is also known as an option Button.
• RadioButton control is used to give single select option to the user from
multiple items.
• A RadioButton control is rounded in shape.
• The prefix of the RadioButton is either “opt” or “rad”.
• We can Check or Uncheck the RadioButton.
• We can take RadioButton on the form when multiple options are there and
selection is only one.
• When the user checks one radio button within a group, the others get
unchecked.
• A single RadioButton on a form doesn’t make much sense.
• All RadioButton in the same group must have the same groupName
property.
ASP.NET Server Controls
• Property :
Property Description
AutoPostBack A Boolean value that specifies whether
the form should be posted immediately
after the Checked property has changed
or not.
Default is false.
Checked A Boolean value that specifies whether
the radio button is checked or not.
GroupName The name of group to which this radio
button belongs.
It is used a group a set of RadioButtons
so only one of them can be selected at
runtime.
Text The text next to the radio button.
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td> Select Gender
</td>
<td>Name</td>
<td>
<asp:RadioButton ID=“optMale” runat=“server” Text=“Male”
GroupName=“Gen” AutoPostBack=“True” />
<asp:RadioButton ID=“optFemale” runat=“server” Text=“Female”
GroupName=“Gen” AutoPostBack=“True” />
</td>
</tr>
ASP.NET Server Controls
<tr>
<td>
<asp:Image ID=“Image1” runat=“server” Width=“100px” />
</td>
</tr>
<tr>
<td>Select Year
</td>
<td>
<asp:RadioButton ID=“optFy” runat=“server” Text=“FY” GroupName=“year” />
<asp:RadioButton ID=“optSy” runat=“server” Text=“SY” GroupName=“year” />
<asp:RadioButton ID=“optTy” runat=“server” Text=“TY” GroupName=“year” />
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void optMale_CheckedChanged(object sender , EventArgs e)


{
Image1.ImageUrl = “~\\img\\boy.gif”;
}
protected void optFemale_CheckedChanged(object sender , EventArgs e)
{
Image1.ImageUrl = “~\\img\\girl.gif”;
}
ASP.NET Server Controls
5. AutoPostBack Property :
• It’s a property of RadioButton, CheckBox, ListBox, Dropdown list etc..
• This property is Boolean. It can store either true or false.
• Default is false.
• If we want to fire event of any of the above listed control then set to true.
• When we set true then the form containing that specific control is
automatically posted back to server whenever the event of that a particular
control occurs.
• Example :
 Webpage containing three dropdownlist controls, first for country, second
for state and third for city, according to change of country state will change
and according to state city should be change.
ASP.NET Server Controls
6. CheckBox Control :
• The CheckBox Web server controls provides a way for users to switch
between true-false or yes-no options.
• Ideally CheckBox control is used to give option to the user.

• Property :

Property Description
AutoPostBack Form is automatically posted back when
CheckBox is checked or Unchecked.
Checked If true, Check Box is checked by default.
ASP.NET Server Controls
HTML View :
<div>
<asp:CheckBox ID=“chkPan1” runat=“server” Text=“Show Personal Detail”
AutoPostBack=“True” />
<asp:CheckBox ID=“chkPan2” runat=“server” Text=“Show Office Detail”
AutoPostBack=“True” />
<asp:CheckBox ID=“chkPan3” runat=“server” Text=“Show Other”
AutoPostBack=“True” />
</div>
<asp:Panel ID=“Panel1” runat=“server” Text=“Personal Detail”
Visible=false> </asp:Panel>
<asp:Panel ID=“Panel2” runat=“server” Text=“Office Detail” Visible=false>
</asp:Panel>
<asp:Panel ID=“Panel3” runat=“server” Text=“Other Detail” Visible=false>
</asp:Panel>
ASP.NET Server Controls
Coding View :

protected void chkPan1_CheckedChanged(object sender , EventArgs e)


{
if (chkPan1.Checked == true)
{
Panel1.Visible = true;
}
else
{
Panel1.Visible = false;
}
}
ASP.NET Server Controls
protected void chkPan2_CheckedChanged(object sender , EventArgs e)
{
if (chkPan2.Checked == true)
{
Panel2.Visible = true;
}
else
{
Panel2.Visible = false;
}
}
ASP.NET Server Controls
protected void chkPan3_CheckedChanged(object sender , EventArgs e)
{
if (chkPan3.Checked == true)
{
Panel3.Visible = true;
}
else
{
Panel3.Visible = false;
}
}
ASP.NET Validation Control
• One of the main tasks for every web developer is to check for errors while
developing web pages.
• According to the server side terminology, this concept is called as
validation.
• A Validation server control is used to validate the data of an input control.
• With these controls you can force the user to input correct entry into the
appropriate fields.
• ASP.NET provides a set of validation controls that provide an easy to use
but powerful way to check for errors and if the data does not pass
validation, it will display an error messages to the user.
• Validation is important part of any web application. User’s input must
always be validated before sending across different layers of the
application.
• You can check for required fields, range of values, minimum and
maximum values and specific patterns.
ASP.NET Validation Control
Control Name Description
RequiredField Validator Use it to ensure that a value has been entered into a
control.
Range Validator Checks that the user enters a value that falls between two
values.
RegularExpression Ensure that the value of an input control matches a
Validator specified pattern, ensure data validity using a specific
regular expression.
Compare Validator Checks a value entered into a control with a predefined
value or with the contents of another control.
Custom Validator Allows you to write a method to handle the validation of
the value entered.
Validation Summary Displays a report of all validation errors occurred in a web
page.
ASP.NET Validation Control

Property Description
ControlToValidate ID of the control to validate. It’s compulsory property.
SetFocusOnError Whether the validator sets focus on the control when
invalid.
ErrorMessage Message to display in a Validation Summary when the
validated control is invalid.
You can write error message here.

Text Text to display for the validator when the validated control
is invalid.
ASP.NET Validation Control
1. RequiredField Validation Control :
• Due to RequiredField Validator control the associated Control cannot be
empty.
• The RequiredField Validator control is simple validation control, which
checks to see if the data is entered for the input control.
• The RequiredField Validator control ensures that the user does not skip an
entry.
• The control fails validation if the value it contains does not change from its
initial value when validation is performed. If all the fields in the page are
valid, the page is valid.
• You can have a RequiredField Validator control for controls on which you
wish to enforce Compulsory Filed rule.
ASP.NET Validation Control

Property Description
ControlToValidate The id of the control to validate.
Display The display behaviour for the validation control.
Legal values are : None
Static The control display an error message if validation fails.
Space is reserved on the page for the message even if the
input passes validation.

Dynamic The control display an error message if validation fails.


Space is not reserved on the page for the message even if
the input passes validation.
ErrorMessage The text to display in the ValidationSummary control
when Validation fails.
Initial Value Specifies the starting value of the input control.
Text The message to display when validation fails.
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td colspan = “4”>
<h4>Fill your personal Info</h4>
</td>
</tr>
<tr>
<td>Name</td>
<td> <img src = “img/ar1.gif” /> </td>
<td>
<asp:TextBox ID=“txtName” runat=“server”>
</asp:TextBox>
</td>
ASP.NET Server Controls
<td>
<asp:RequiredFieldValidator ID=“valName” runat=“server”
ControlToValidate = “txtName”>Enter Name
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Age</td>
<td> <img src = “img/ar2.gif” /> </td>
<td>
<asp:TextBox ID=“txtAge” runat=“server”>
</asp:TextBox>
</td>
ASP.NET Server Controls
<td>
<asp:RequiredFieldValidator ID=“valAge” runat=“server” ControlToValidate
= “txtName” ErrorMessage=“RequiredFieldValidator”>*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>City</td>
<td> <img src = “img/ar3.gif” /> </td>
<td>
<asp:DropDownList ID=“cmbCity” runat=“server”>
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Ahmedabad</asp:ListItem>
<asp:ListItem>Surat</asp:ListItem>
ASP.NET Server Controls
<asp:ListItem>Jamnagar</asp:ListItem>
<asp:ListItem>Rajkot</asp:ListItem>
<asp:ListItem>Bhavnagar</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID=“valCity” runat=“server”
ControlToValidate=“cmbCity” ErrorMessage=“RequiredFieldValidator”
InitialValue=“Select” >Select City </asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan=“3”>
ASP.NET Server Controls
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit”
CausesValidation=“True” />

<asp:Button ID=“btnClear” runat=“server” Text=“Clear”


CausesValidation=“False” />

</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void btnClear_Click(object sender , EventArgs e)


{
txtName.Text = “”;
txtAge.Text = “”;
cmbCity.SelectedIndex = 0;
}
ASP.NET Server Controls
2. RangeValidator Control :
• The RangeValidator Server control make sure that the end user value of
selection provided is between a specified ranges.
• The attributes that are necessary to this control are : MaximumValue,
MinimumValue and Type.

• Property :
Property Description
Type Data type of values for comparison.
Maximum Value Maximum value for the control being
validated.
Minimum Value Minimum value for the control being
validated.
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td colspan = “4”>
<h4>Demo of RangeValidator</h4>
</td>
</tr>
<tr>
<td> Fname </td>
<td> <img src = “img/ar1.gif” /> </td>
<td>
<asp:TextBox ID=“txtFName” runat=“server”>
</asp:TextBox>
</td>
ASP.NET Server Controls
<tr>
<td> Mname </td>
<td> <img src = “img/ar2.gif” /> </td>
<td>
<asp:TextBox ID=“txtMName” runat=“server”>
</asp:TextBox>
</td>
<td>
<asp:RangeValidator ID=“valMname” runat=“server”
ErrorMessage=“RangeValidator” ControlToValidate=“txtMname”
MaximumValue=“z” MinimumValue=“a”> Enter valid char
</asp:RangeValidator>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td> Age </td>
<td> <img src = “img/ar3.gif” /> </td>
<td>
<asp:TextBox ID=“txtAge” runat=“server”>
</asp:TextBox>
</td>
<td>
<asp:RangeValidator ID=“valAge” runat=“server”
ErrorMessage=“RangeValidator” ControlToValidate=“txtAge”
MaximumValue=“25” MinimumValue=“18” Type=“Integer”
SetFocusOnError=“True”> Enter Age &gt; 18 and &lt; 25
</asp:RangeValidator>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td> Date of Next Lecture </td>
<td> <img src = “img/ar4.gif” /> </td>
<td>
<asp:TextBox ID=“txtDON” runat=“server”>
</asp:TextBox>
</td>
<td>
<asp:RangeValidator ID=“valcal” runat=“server”
ErrorMessage=“RangeValidator” ControlToValidate=“txtDON” Type=“Date”
SetFocusOnError=“True”> Date should be within 5 days
</asp:RangeValidator>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td colspan=“3”>
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit”
CausesValidation=“True” />
<asp:Button ID=“btnClear” runat=“server” Text=“Clear”
CausesValidation=“False” />
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void Page_Load(object sender , EventArgs e)


{
if (!Page.IsPostBack)
{
valcal.MinimumValue =
DateTime.Now.Date.ToShortDateString() ;
valcal.MaximumValue =
DateTime.Now.Date.ToShortDateString() ;
}
}
ASP.NET Server Controls
protected void btnClear_Click(object sender , EventArgs e)
{
txtFName.Text = “ ” ;
txtMName.Text = “ ” ;
txtAge.Text = “ ” ;
txtDON.Text = “ ” ;
}
ASP.NET Server Controls
3. RegularExpression Control :
• The RegularExpressionValidator control confirms that the entry matches a
pattern defined by a regular expression.
• It checks that the value in the control matches a specified regular
expression. If the validate control is empty, no validation takes place.
• This type of validation allows you to check for predictable sequences of
characters, such as those in Zip code , URL , Email address , Telephone
number , Postal code and so on.
• If you don’t find your desired regular expression, you can create your
custom one.
• RegularExpressionValidator uses main property to perform its
validation : ValidationExpression contains the regular expression to
match.
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td colspan = “4”>
<h4>Demo of RegularExpression</h4>
</td>
</tr>
<tr>
<td> Name </td>
<td> <img src = “img/ar1.gif” /> </td>
<td>
<asp:TextBox ID=“txtName” runat=“server”>
</asp:TextBox>
</td>
ASP.NET Server Controls
<tr>
<td> Email </td>
<td> <img src = “img/ar2.gif” /> </td>
<td>
<asp:TextBox ID=“txtEmail” runat=“server”>
</asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID=“valEmail” runat=“server”
ErrorMessage=“RegularExpressionValidator” Text=“Enter valid Email”
ControlToValidate=“txtEmail” ValidationExpression=“\w+([-+.’]\w+)*@\
w+([-.]\w+)*\.\w+([-.]\w+)*”>
</asp:RegularExpressionValidator>
</td>
</tr>
ASP.NET Server Controls
</tr>
<tr>
<td> URL </td>
<td>
<img src = “img/ar4.gif” />
</td>
<td>
<asp:TextBox ID=“txtURL” runat=“server”>
</asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID=“valURL” runat=“server”
ErrorMessage=“RegularExpressionValidator” Text=“Enter valid URL”
ControlToValidate=“txtURL” ValidationExpression=“http(s)?://([\w-]+\.)+[\
w-]+(/[\w- ./?%&amp;=]*)?”> </asp:RegularExpressionValidator>
ASP.NET Server Controls
</td>
</tr>
<tr>
<td> Mobile Phone </td>
<td> <img src=“img/ar5.gif” /> </td>
<td>
<asp:TextBox ID=“txtMob” runat=“server”>
</asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID=“valMob” runat=“server”
ErrorMessage=“RegularExpressionValidator” Text=“10 digits”
ControlToValidate=“txtMob” ValidationExpression=“\d{10}”>
</asp:RegularExpressionValidator>
ASP.NET Server Controls
</td>
</tr>
<tr>
<td> Stream </td>
<td> <img src=“img/ar6.gif” /> </td>
<td>
<asp:TextBox ID=“txtStream” runat=“server”>
</asp:TextBox>
</td>
<td> (BCA , BBA , BCOM)
<asp:RegularExpressionValidator ID=“valStream” runat=“server”
ErrorMessage=“RegularExpressionValidator” Text=“10 digits”
ControlToValidate=“txtStream” ValidationExpression=“B..”>Invalid Stream
</asp:RegularExpressionValidator>
ASP.NET Server Controls
</td>
</tr>
<tr>
<td colspan=“3”>
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit”
CausesValidation=“True” />
<asp:Button ID=“btnClear” runat=“server” Text=“Clear”
CausesValidation=“False” />
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void btnClear_Click(object sender , EventArgs e)


{
txtEmail.Text = “ ” ;
txtMob.Text = “ ” ;
txtName.Text = “ ” ;
txtStream.Text = “ ” ;
txtURL.Text = “ ” ;
}
ASP.NET Server Controls
4. CompareValidator Control :
• It is used to compare the value of one input control to the value of another
input control or to a fixed value.
• The two controls are compared with the type of comparison specified in
the Operator attribute.
• The Operator attribute can contain Equal, Greater Than, Less Than Or
Equal etc..
• In other words, it checks that the value in the validated control matches the
value in another control or a specific value. The data type and comparison
operation can be specified.
• The most important properties in the CompareValidator are
ValueToCompare, ControlToCompare, Operator and type.
• If the expression evaluates be true, the validation result is valid.
ASP.NET Server Controls
Properties Description
ControlToCompare The name of the control to compare with
ControlToValidate The id of the control to validate
Operator The type of comparison to perform
Type Specifies the data type of the values to
compare
ValueToCompare A specified value to compare with
ASP.NET Server Controls
HTML View :
<%@ Page Language=“C#” AutoEventWireup=“true”
CodeFile=“Default.aspx.cs” Inherits=“_Default” %>
<head runat=“server”>
<title>Demo CompareValidator</title>
</head>
<body>
<form id=“form1” runat=“server”>
<table>
<tr>
<td colspan = “5”>
<h4>Demo of CompareValidator</h4>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td> UserName </td>
<td> <img src=“img/ar1.gif” /> </td>
<td>
<asp:TextBox ID=“txtUName” runat=“server”>
<asp:TextBox>
</td>
</tr>
<tr>
<td> Password </td>
<td> <img src=“img/ar2.gif” /> </td>
<td>
<asp:TextBox ID=“txtPwd” runat=“server”>
<asp:TextBox>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td> Confirm Password </td>
<td> <img src=“img/ar3.gif” /> </td>
<td>
<asp:TextBox ID=“txtCPwd” runat=“server”>
<asp:TextBox>
</td>
<td>
<asp:CompareValidator ID=“valCPwd” runat=“server”
ControlToValidate=“txtCPwd” ControlToCompare=“txtPwd”
ErrorMessage=“CompareValidator”>
</asp:CompareValidator>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td> DOB </td>
<td> <img src=“img/ar4.gif” /> </td>
<td>
<asp:TextBox ID=“txtDOB” runat=“server”>
<asp:TextBox>
</td>
<td>
<asp:CompareValidator ID=“valDOB” runat=“server”
ControlToValidate=“txtDOB” ErrorMessage=“CompareValidator”
Operator=“DataTypeCheck” Type=“Date”> Invalid Date
</asp:CompareValidator>
</td>
ASP.NET Server Controls
<asp:CompareValidator ID=“valDOBLess” runat=“server”
ControlToValidate=“txtDOB” ErrorMessage=“CompareValidator”
Operator=“Less Than” Type=“Date”> Less than today
</asp:CompareValidator>
</td>
</tr> <tr>
<td colspan=“5”>
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit”
CausesValidation=“True” />
<asp:Button ID=“btnClear” runat=“server” Text=“Clear”
CausesValidation=“False” />
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void Page_Load(object sender , EventArgs e)


{
valDOBLess.ValueToCompare = DateTime.Now.ToString(“d”);
}

protected void btnClear_Click(object sender , EventArgs e)


{
txtPwd.Text = “ ” ;
txtCPwd.Text = “ ” ;
txtUName.Text = “ ” ;
}
ASP.NET Server Controls
5. CustomValidator Control :
• Allows you to develop custom validation.
• The CustomValidator control allows you to write a method to handle the
validation of the value entered.
• Performs user-defined validation on an input control using a specified
function.
• The CustomValidator control allows you to build your own client-side or
server-side validations that can then be easily applied to your web forms.
• The CustomValidator control calls a user-defined function to perform
validations that the standard validators can’t handle.
• The Value property is the value to be validate and the IsValid property is a
Boolean used to set the return result of the validation.
ASP.NET Server Controls
HTML View :
<table>
<tr>
<td colspan = “4”>
<h4>Demo of CustomValidator</h4>
</td>
</tr>
<tr>
<td> UserName </td>
<td> <img src=“img/ar1.gif” /> </td>
<td>
<asp:TextBox ID=“txtUName” runat=“server”>
<asp:TextBox>
</td>
ASP.NET Server Controls
<td>
<asp:CustomValidator ID=“valName” runat=“server”
ControlToValidate=“txtUName” ErrorMessage=“CustomValidator”> Length
</asp:CustomValidator>
</t2>
</tr>
<tr>
<td> Even No </td>
<td> <img src=“img/ar1.gif” /> </td>
<td>
<asp:TextBox ID=“txtNo” runat=“server”>
<asp:TextBox>
</td>
ASP.NET Server Controls
<td>
<asp:CustomValidator ID=“valEven” runat=“server”
ControlToValidate=“txtNo” ErrorMessage=“CustomValidator”> Oddno
</asp:CustomValidator>
</td>
</tr>
<td colspan=“4”>
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit”
CausesValidation=“True” />
<asp:Button ID=“btnClear” runat=“server” Text=“Clear”
CausesValidation=“False” />
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :

protected void valName_ServerValidate(object sender , EventArgs e)


{
string str = null;
str = args.value;
if (str.Length > 8 && str.Length <18)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
ASP.NET Server Controls
protected void valEven_ServerValidate(object sender , EventArgs e)
{
int no;
no = Convert.ToUInt16(args.value);
if (no % 2 == 0)
{
args.IsValid = true;
}
else
{
args.isValid = false;
}
}
ASP.NET Server Controls
protected void btnClear_Click(object sender , EventArgs e)
{
txtUName.Text = “ ” ;
txtNo.Text = “ ” ;
}
ASP.NET Server Controls
6. Validation Summary Control :
• The Validation Summary control is reporting control, which is used by the
other validation control on a page.
• The Validation Summary control is used to display a summary of all
validation errors occurred in a web page.
• You can use this validation control to consolidate error reporting for all the
validation errors that occur on a page instead of leaving this up to each and
every individual validation control.
• Both ErrorMessage and Text properties are used to display error messages.
Text error message have precedence.
ASP.NET Server Controls
Properties Description
DisplayMode Format for error summary display.
ShowMessageBox Whether to display a message box on
error in up level browsers.
ShowSummary Whether to display the summary text on
the page.
HeaderText Header text to display in the Summary.
ASP.NET Server Controls
HTML View :
<%@ Page Language=“C#” AutoEventWireup=“true”
CodeFile=“Default.aspx.cs” Inherits=“_Default” %>
<head runat=“server”>
<style type = “text/css”>
.style1
{
width : 50%;
font-size : medium;
}
td
{

}
ASP.NET Server Controls
td
{
font-size : medium;
font-family : Verdana;
color : RoyalBlue;
}
.head
{
font-family : Verdana;
color : red;
}
</style>
</head>
<body>
ASP.NET Server Controls
<form id = “form1” runat = “server”>
<div>
<table class = “style1”>
<tr>
<td colspan = “3” class=“head”>
Aspiration-Personal Information
</td>
</tr>
<tr>
<td> Name </td>
<td>
<asp:TextBox ID=“txtName” runat=“server”>
</td>
ASP.NET Server Controls
<td>
<asp:RequiredFieldValidator ID=“RequiredFieldValidator1” runat = “server”
ErrorMessage=“Enter name” ControlToValidate=“txtName”
SetFocusOnError=“True”>
<asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td> Last Name </td>
<td>
<asp:TextBox ID=“txtSName” runat=“server”>
</td>
ASP.NET Server Controls
<td>
<asp:RequiredFieldValidator ID=“RequiredFieldValidator2” runat = “server”
ErrorMessage=“Enter Last Name” ControlToValidate=“txtSName”
SetFocusOnError=“True”>
<asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td> Age </td>
<td>
<asp:TextBox ID=“txtAge” runat=“server”>
</td>
ASP.NET Server Controls
<td>
<asp:RangeValidator ID=“RangeValidator1” runat = “server”
ErrorMessage=“25&gt; and &lt;40” ControlToValidate=“txtAge”
Type=“Integer” MaximumValue=“40” MinimumValue=“25”>
<asp:RangeValidator>
</td>
</tr>
<tr>
<td> Email </td>
<td>
<asp:TextBox ID=“txtEmail” runat=“server”>
</td>
ASP.NET Server Controls
<td>
<asp:RegularExpressionValidator ID=“RegularExpressionValidator1” runat =
“server” ErrorMessage=“Wrong Email” ControlToValidate=“txtEmail”
ValidationExpression=“[\w]+@[\w]+\.(com|net|org|co\.th|ac\.th|or\.th|go\.th)”>
<asp:RangeValidator>
</td>
</tr>
<tr>
<td> Password </td>
<td>
<asp:TextBox ID=“txtCode” runat=“server” TextMode=“Password” />
</td>
ASP.NET Server Controls
<tr>
<td> Confirm Password </td>
<td>
<asp:TextBox ID=“txtConfirm” runat=“server” TextMode=“Password” />
</td>
<td>
<asp:CompareValidator ID=“CompareValidator1” runat=“server”
ControlToCompare=“txtCode” ControlToValidate=“txtConfirm”
ErrorMessage=“The password disagree !”>
</asp:CompareValidator>
</td>
</tr>
ASP.NET Server Controls
<tr>
<td>
<asp:Button ID=“btnSave” runat=“server” Text=“Submit” />
</td>
</tr>
<tr>
<td>
<asp:ValidationSummary ID= “ValidationSummary1” runat=“server”
HeaderText=“All the errors” DisplayMode=“List” ShowMessageBox=“True”
ShowSummary=“False” >
<asp:ValidationSummary>
</td>
</tr>
</table> </div> </form> </body>
ASP.NET Rich Server Controls
1. AdRotator Control :
• The AdRotator control is used to display a sequence of ad images.
• Remember that the effect of this control does not give effect like Flash file
or Animated gif.
• It presents ad images that, when clicked, navigate to a new web location.
• Generally, AdRotator control is used to show the advertisement banner on
the page. The source of advertisement banners are written in a XML file in
a certain format.
• AdRotator control displays an image and updates both Image and target
URL each time the page refreshes. When user clicks on the image, user is
redirected to the target URL.
• Each time the page is loaded into the browser, an ad is randomly selected
from a predefined list.
ASP.NET Rich Server Controls
• This control uses an XML file to store the ad information. The XML file
must begin and end with an <Advertisement> tag. Inside the
<Advertisements> tag there may be several <Ad> tags which defines each
ad.
• Property :

Property Description
AdvertisementFile The path to the XML file that contains ad information.
KeywordFilter Specifies a keyword to filter for specific types of
advertisements in the XML advertisement file.
Target • _blank : Renders the content in a new window without
frames.
• _parent : Renders the content in the immediate frameset
parent.
• _self : Renders the content in the frame with focus.
• _top : Renders the content in the full window without
frames.
ASP.NET Rich Server Controls
Element Description
<Advertisements> Refers to the opening tag for XML file.
<Ad> Refers to the tag that is used for each advertisement.
<ImageUrl> The absolute or relative URL to an image file.
<AlternateText> This text is displayed if the image specified in ImageUrl is not
accessible. This text also appears as a ToolTip for the
advertisement.
<Keyword> A category for the advertisement that you can filter by.
<Impressions> A number that indicates the importance of the ad in the
schedule of rotation relative to the other ads in the file.
<NavigateUrl> The URL of a page to link to if the user clicks the ad.
ASP.NET Rich Server Controls
• Basic Structure:
<Advertisements>
<Ad>
<ImageUrl>images/krunal.gif</ImageUrl>
<NavigateUrl>http://www.krunal.com</NavigateUrl>
<AlternateText>Krunal.com</AlternateText>
<Keyword>Coaching Computer</Keyword>
<Impressions>80</Impressions>
</Ad>
</Advertisements>
ASP.NET Rich Server Controls
• Example:
<?xml version =“1.0” encoding=“utf-8” ?>
<Advertisements>
<Ad>
<ImageUrl>images/kurkure.jpg</ImageUrl>
<NavigateUrl>http://www.kurkure.com</NavigateUrl>
<AlternateText> kurkure </AlternateText>
<Keyword>Children</Keyword>
<Impressions>80</Impressions>
</Ad>
ASP.NET Rich Server Controls
<Ad>
<ImageUrl>images/maggie.jpg</ImageUrl>
<NavigateUrl>http://www.maggie.com</NavigateUrl>
<AlternateText> Maggie </AlternateText>
<Keyword>Children</Keyword>
<Impressions>80</Impressions>
</Ad>
<Ad>
<ImageUrl>images/lux.jpg</ImageUrl>
<NavigateUrl>http://www.lux.com</NavigateUrl>
<AlternateText> Lux </AlternateText>
<Keyword>Beauty</Keyword>
<Impressions>100</Impressions>
</Ad>
ASP.NET Rich Server Controls
<Ad>
<ImageUrl>images/Ponds.jpg</ImageUrl>
<NavigateUrl>http://www.Ponds.com</NavigateUrl>
<AlternateText> Dairy </AlternateText>
<Keyword>Beauty</Keyword>
<Impressions>80</Impressions>
</Ad>

</Advertisements>
ASP.NET Login Controls
• There are seven types of Login controls.

1. Login Control : Login form


2. Login Status : login or logout link
3. Login Name : display username
4. CreateUserWizard : user registration form
5. Change Password : allows the user to change their password
6. Password Recovery : allows the user to change their password
7. Login View : Display content depending on logged in or out.
ASP.NET Login Controls
1. Login Control :
• Login control provides a ready to use user interface that can be used as a
login interface in the web site.
• The control includes user name and password text boxes and a check box
for users who want to compromise password security by saving their
passwords on the machine.
• The control exposes properties through which you can change the text and
appearance of the control.

Syntax :
<asp:Login ID=“Login1” runat=“server”>
</asp:Login>
ASP.NET Login Controls
2. Login Status :
• The Login Status control automatically detects the user’s authentication
status and displays the appropriate Login/Logout options.
• It display either Login (if user is not logged in) or Logout (if user is logged
in).
• Clicking on the Login button will redirect the user to the login page for the
website.
• The Login status control will retrieve the login page URL from the
Web.Config file forms authentication section.
• Clicking on the Logout button will clear the user’s authentication status
and by default refresh the page that they are currently viewing.
ASP.NET Login Controls
3. Login Name :
• The Login Name control is used to display current logged in user name.
• It uses the value returned by calling Page.User.Identify.
• If the user is not currently logged in then the control does not occupy the
space.
• If the user is not logged in, this page doesn’t render anything. This controls
gets the value by using Page.Identify.Name.

4. CreateUserWizard :
• CreateUserWizard control is a ready to use control that is used to create a
new user to the website.
• In other word we can say that it a replacement of Registration form of a
website.
• It has few steps to complete the registration process.
ASP.NET Login Controls
• The control gathers a user name, a password, a confirmation or password,
an e-mail address, a security question, and a security answer.
• This information is used to authenticate users and recover user password, if
necessary.
ASP.NET Login Controls
5. ChangePassword Control :
• ChangePassword control is ready to use control to help users to change
their password.
• An authenticated user may change his or her password by supplying the
original password and a new password.
• If the original password is correct, the user password is changed to the new
password. The control also includes support for sending an e-mail message
about the new password.
ASP.NET Login Controls
6. PasswordRecovery Control :
• The PasswordRecovery control provides the functionality to retrieve or
reset a user’s password based on their username.
• The control collects the user’s account name, and then follows up with a
security question.
• The control does not support displaying the password to the user in their
web browser.
• The control either e-mails the current password to the user or creates a new
one.
• The PasswordRecovery control requires that your application can forward
e-mail message to a Simple Mail Transfer Protocol (SMTP) server.
ASP.NET Login Controls
7. LoginView Control :
LoginView control is very simple yet very powerful and customizable.
It allows user to customize its view for both anonymous user and logged
in user.
The LoginView control is very like the optional login page mentioned
earlier.
The LoginView control automatically detects a user’s authentication
status and role and matches that information to appropriate template of
information to display to that user.
The LoginView displays the login status via the display templates
Anonymous Template and LoggedIn Template.
The control renders a different template depending on the status of the
user.
You
a n k
T h

You might also like