Asp.net slide
Trang 1Session 5
Web Server Controls
Trang 2 The @ Page directive is used to specify attributes that affect the
code in the aspx page.
The <script> section is where most of the code for providing the required functionality is written.
There are two types of server controls:
HTML Controls
Web Controls
All event procedures receive two arguments from the events:
The event sender
The class instance that holds data for the event
The _VIEWSTATE control is a hidden control that is added to the form when the form is submitted to the server.
It is possible to check whether a aspx page is posted back to the server, with the help of the IsPostBack property of the page.
Trang 3Review Contd…
ASP.NET has several built-in objects that are used to provide the
required functionality in an ASP.NET application They are the following:
The base directory is called the virtual root, and the directory in which
we store the application files is called the virtual directory.
The Request object corresponds to the request message of the HTTP protocol, and the Response object corresponds to the response
message of the HTTP protocol.
The Form.Get method of the Request object is used to retrieve the data submitted by the user.
The Redirect method of the Response object is used to redirect the user to another page.
Trang 4 Explain Web Controls
Explain why controls are objects
Use Controls for Text Entry
Use Controls for Control Transfer
Use Controls for Selection
Discuss Rich Controls
Trang 5Web Controls
ASP.NET Controls
Intrinsic
List
Rich
Validation
Trang 6Web Controls as Objects
Like objects, web controls possess methods and properties, and respond to events
It is possible to set the properties and call the
methods of the web controls once they are
included onto the web page
Server-side code can be written for the web
control to respond to events that occur on the
client-side
Trang 7Web Controls as Objects - Example
<html>
<script language="C#" runat ="server" >
void Button1click(Object Src, EventArgs E){
lblMessage.Text =Src.ToString();
btnButton1.Enabled = false;
btnButton2.Visible = true;
}void Button2click(Object Src, EventArgs E){
Trang 8Web Controls as Objects - Example
<asp:button id="btnButton1" type = submit text= "Click
me to know who I am" OnClick="Button1click" runat = "server" />
<asp:button id="btnButton2" type = submit text=
"Clear the label" visible=false OnClick="Button2click" runat = "server" /
Trang 9Web Controls as Objects - Output
Output of Example 1 Before clicking the button
Output of Example 1
After clicking the button
Trang 11Text Entry - Intrinsic Control
Trang 12Posting data back
to the server
Navigate between the pages
Save or access data from the server
Control Transfer - Intrinsic Control
Trang 13Control Transfer
Trang 14<asp:checkbox id="chkbx1" Text="Select Me" runat="server"/>
Intrinsic Control: Selection
<asp:CheckBoxList id="CheckBoxList1" runat="server">
<asp:ListItem Value="Maths">Maths</asp:ListItem>
<asp:ListItem Value="Science">Science</asp:ListItem>
<asp:ListItem Value="English">English</asp:ListItem>
<asp:ListItem Value="Computers">Computers</asp:ListItem>
</asp:CheckBoxList>
Trang 15Intrinsic Control: Selection
<asp:radiobutton id ="radbt1" Text =" Radio Button no 1"
Trang 16<asp:listbox id="lstbx1" SelectionMode=”Single”
runat="server"/>
Intrinsic Control: Selection
<asp:RadioButtonList id="RadioButtonList1" runat="server">
Trang 17ArrayList arrlist= new
<asp:listbox id="lbs" runat="server">
<asp:ListItem> One </asp:ListItem>
<asp:ListItem> Two </asp:ListItem>
<asp:ListItem> Three </asp:ListItem>
</asp:listbox>
<asp:dropdownlist id= "ddl"
runat="server" >
<asp:ListItem> One </asp:ListItem>
<asp:ListItem> Two </asp:ListItem>
<asp:ListItem> Three </asp:ListItem>
</asp:dropdownlist>
Intrinsic Control: Selection –
Methods to populate data
Trang 18<asp:panel id="panel1" Visible="False" runat="server" >
<asp:textbox id="OldPwd" textmode="password"
runat="server"/>
<asp:textbox id="NewPwd" textmode="password"
runat="server"/>
</asp:panel>
Container controls can contain other controls
One of the main uses of container controls, is that the
visibility of a group of controls can be changed at one
point by placing them in a container control, and
setting the property of the container control
Container controls can contain other controls
One of the main uses of container controls, is that the
visibility of a group of controls can be changed at one
point by placing them in a container control, and
setting the property of the container control
Container
Trang 19Used for changing the
advertisements on
the web pages
Gives full functionality of
a calendar
Rich Controls
Trang 20Absolute or relative Url of the image file
Target website after clicking the Ad
Text that will be displayed when the mouse is rolled over the
image
Category assigned to the ad
Priority of the advertisement in the schedule of rotation
AdRotator
Trang 21AdRotator – Output
Trang 22Calendar Control
Simple to use, and gives us the full functionality
of a calendar
The calendar can be created and formatted to
suit the look and feel of the web page
Trang 24Calendar Control - Example
<html>
<script language="C#" runat ="server" >
void date_changed(Object sender,EventArgs e)
Trang 25Calendar Control - Example
Trang 26Calendar Control - Example
Trang 27Calendar Control - Output
Trang 29Summary Contd…
There are four controls in ASP.NET that can be used to navigate
between pages, or transfer control to a specified page:
ASP.NET provides container controls, that is, the controls that
can contain other controls.
ASP.NET provides two rich controls:
AdRotator Control
Calendar Control