Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd…...
Transcript of Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd…...
![Page 1: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/1.jpg)
Session 5
Web Server Controls
![Page 2: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/2.jpg)
Exploring ASP.NET / Session 5 / 2 of 29
Review
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.
![Page 3: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/3.jpg)
Exploring ASP.NET / Session 5 / 3 of 29
Review 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: Request Response Application Session Server ObjectContext
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.
![Page 4: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/4.jpg)
Exploring ASP.NET / Session 5 / 4 of 29
Objectives
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
![Page 5: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/5.jpg)
Exploring ASP.NET / Session 5 / 5 of 29
Web Controls
ASP.NET
Controls
Intrinsic
List
Rich
Validation
![Page 6: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/6.jpg)
Exploring ASP.NET / Session 5 / 6 of 29
Web 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
![Page 7: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/7.jpg)
Exploring ASP.NET / Session 5 / 7 of 29
Web 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) { lblMessage.Text=""; btnButton2.Visible = false; btnButton1.Enabled = true; } </script>
![Page 8: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/8.jpg)
Exploring ASP.NET / Session 5 / 8 of 29
Web Controls as Objects - Example
<body> <form runat="server"> <asp:label id="lblMessage" text="Click on the button"
runat="server"/> <br><br> <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" />
<br> </form> </body> </html>
![Page 9: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/9.jpg)
Exploring ASP.NET / Session 5 / 9 of 29
Web Controls as Objects - Output
Output of Example 1
Before clicking the button
Output of Example 1
After clicking the button
![Page 10: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/10.jpg)
Exploring ASP.NET / Session 5 / 10 of 29
<input type=
“checkbox”>
<input type= “radio”>
<asp:CheckBox>
<asp:RadioButton>
<asp:TextBox rows=“1”>
<asp:TextBox rows=“10”>
<input type= “text”>
< textarea>
Intrinsic Controls
![Page 11: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/11.jpg)
Exploring ASP.NET / Session 5 / 11 of 29
<asp:textbox id="name"
runat="server"/>
<asp:textbox id="add"
textmode="multiline" rows=“10"
columns="10" runat="server"/>
<asp:textbox id="pwd"
textmode="password" runat="server"/>
Text Entry - Intrinsic Control
![Page 12: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/12.jpg)
Exploring ASP.NET / Session 5 / 12 of 29
Posting data back
to the server
Navigate between the pages
Save or access
data from the
server
Control Transfer - Intrinsic Control
![Page 13: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/13.jpg)
Exploring ASP.NET / Session 5 / 13 of 29
Control Transfer
![Page 14: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/14.jpg)
Exploring ASP.NET / Session 5 / 14 of 29
<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>
![Page 15: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/15.jpg)
Exploring ASP.NET / Session 5 / 15 of 29
Intrinsic Control: Selection
<asp:radiobutton id ="radbt1" Text =" Radio Button no 1"
groupname="radio" runat="server"/>
<asp:radiobutton id ="radbt2" Text =" Radio Button no 2"
groupname="radio" runat="server"/>
<asp:radiobutton id ="radbt3" Text =" Radio Button no 3“
groupname="radio" runat="server"/>
![Page 16: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/16.jpg)
Exploring ASP.NET / Session 5 / 16 of 29
<asp:listbox id="lstbx1" SelectionMode=”Single”
runat="server"/>
<asp:dropdownlist id= "dropdnlst1" runat="server" />
Intrinsic Control: Selection
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Yellow">Yellow</asp:ListItem>
</asp:RadioButtonList>
![Page 17: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/17.jpg)
Exploring ASP.NET / Session 5 / 17 of 29
ArrayList arrlist= new
ArrayList();
arrlist.Add ("Four");
arrlist.Add ("Five");
arrlist.Add ("Six");
ddl.DataSource =arrlist;
void Page_Load (Object Src, EventArgs E)
{
ddl.Items.Add("<10");
ddl.Items.Add("10-20");
ddl.Items.Add("20-30");
ddl.Items.Add("30-40");
ddl.Items.Add("40-50");
ddl.Items.Add(">50");
}
<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
![Page 18: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/18.jpg)
Exploring ASP.NET / Session 5 / 18 of 29
<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
![Page 19: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/19.jpg)
Exploring ASP.NET / Session 5 / 19 of 29
Used for changing
the advertisements
on the web pages
Gives full functionality of
a calendar
Rich Controls
![Page 20: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/20.jpg)
Exploring ASP.NET / Session 5 / 20 of 29
<Advertisements>
<Ad>
<ImageUrl> </ImageUrl>
<TargetUrl> </TargetUrl>
<AlternateText>
</AlternateText>
<Keyword> </Keyword>
<Impressions>
</Impressions>
</Ad>
</Advertisements>
Absolute 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
![Page 21: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/21.jpg)
Exploring ASP.NET / Session 5 / 21 of 29
AdRotator – Output
![Page 22: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/22.jpg)
Exploring ASP.NET / Session 5 / 22 of 29
Calendar 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.
Example -
<asp:calendar id="calender1" runat="server"
backcolor="white" forecolor="black"
borderwidth="2" Bordercolor="black"
showgridlines="true"/>
![Page 23: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/23.jpg)
Exploring ASP.NET / Session 5 / 23 of 29
Calendar Control
In most cases, a calendar is used to allow the user to quickly choose a date, instead of manually typing it in
The calendar control responds to two events
Date Changes
Month Changes
![Page 24: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/24.jpg)
Exploring ASP.NET / Session 5 / 24 of 29
Calendar Control - Example <html>
<script language="C#" runat ="server" >
void date_changed(Object sender,EventArgs e)
{
lblMessage.Text= "The date(s) you have selected is:
From " + calendar1.SelectedDates[0].ToShortDateString() + "
to " + calendar1.SelectedDates[calendar1.SelectedDates.Count
- 1].ToShortDateString();
}
void month_changed(Object sender,MonthChangedEventArgs e)
{
lblCur_m.Text= "The current month you selected is: "
+ e.NewDate.ToString("Y");
lblPrev_m.Text= "The previous month you selected is:
" + e.PreviousDate.ToString("Y");
}
</script>
![Page 25: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/25.jpg)
Exploring ASP.NET / Session 5 / 25 of 29
Calendar Control - Example
<body>
<form runat="server">
<table>
<tr>
<td>
<asp:calendar id="calendar1" runat="server"
OnSelectionChanged="date_changed"
OnVisibleMonthChanged="month_changed"
SelectionMode="DayWeekMonth" borderwidth="3"
Bordercolor="red" showgridlines="true">
<SelectedDayStyle BackColor="Yellow" ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
</td>
<td>   
<asp:label id="lblMessage" runat = "server"/><br>
![Page 26: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/26.jpg)
Exploring ASP.NET / Session 5 / 26 of 29
Calendar Control - Example
<br>   
<asp:label id="lblCur_m" runat = "server"/>
<br>
<br>   
<asp:label id="lblPrev_m" runat = "server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
![Page 27: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/27.jpg)
Exploring ASP.NET / Session 5 / 27 of 29
Calendar Control - Output
![Page 28: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/28.jpg)
Exploring ASP.NET / Session 5 / 28 of 29
Summary
There are four sets of controls in ASP.NET: Intrinsic Controls List Controls Rich Controls Validation Controls
Like objects, web controls possess methods and properties and respond to events.
ASP.NET provides three intrinsic controls for entering text. They
are as follows: Single Line Entry Multi-Line Entry Password Entry
![Page 29: Session 5 - trandinhvi.files.wordpress.comExploring ASP.NET / Session 5 / 3 of 29 Review Contd… ASP.NET has several built-in objects that are used to provide the required functionality](https://reader033.fdocuments.net/reader033/viewer/2022060922/60ae246ed4697e59556545b0/html5/thumbnails/29.jpg)
Exploring ASP.NET / Session 5 / 29 of 29
Summary Contd…
There are four controls in ASP.NET that can be used to navigate between pages, or transfer control to a specified page: Button
LinkButton
ImageButton
Hyperlink
ASP.NET provides the following set of selection controls: Checkbox
RadioButton
Listbox
DropDownList
ASP.NET provides container controls, that is, the controls that can contain other controls.
ASP.NET provides two rich controls: AdRotator Control
Calendar Control