Unit-4 - ASP - Net and Web Development - Part-1
Unit-4 - ASP - Net and Web Development - Part-1
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.
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.
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.
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.
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>
</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 :
• 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> </td>
<td>
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit” />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
ASP.NET Server Controls
Coding View :
• 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 :
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.
</td>
</tr>
</table>
ASP.NET Server Controls
Coding View :
• 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 > 18 and < 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 :
}
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> and <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.
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