Download presentation
Presentation is loading. Please wait.
Published byAgus Lie Modified over 6 years ago
1
PROG11044 - Advanced Web Apps
12/9/2018 Session 9.1 Calendar and Validation Controls Using Sessions Wendi Jollymore, ACES
2
Review Postback Page processing ViewState
The return trip from the server Page processing How it works (steps) How the first load is different from postback ViewState Hidden __VIEWSTATE field Using hash array 12/9/2018 Wendi Jollymore, ACES
3
Calendar Control Properties: SelectedDate VisibleDate Note that:
Contains a DateTime object Set when user clicks a date on the control Can be initialized or set at run time VisibleDate The current month that’s visible To set, use the 1st of the month Note that: Selected date can stay the same even as visible date changes 12/9/2018 Wendi Jollymore, ACES
4
Calendar Control Events SelectionChanged VisibleMonthChanged
Occurs when selected date changes User clicks a day, month selector, or week selector Change SelelectionMode property to allow selection of weeks and month VisibleMonthChanged Occurs when user navigates months Does not imply that selection changes! 12/9/2018 Wendi Jollymore, ACES
5
DateTime Class Constructor: DateTime(int year, int month, int day)
Constructs a new DateTime instance for the current year/month/day 12/9/2018 Wendi Jollymore, ACES
6
DateTime Class Properties: Date Day
Contains a DateTime object for the current DateTime instance Time set to midnight Day Contains the day of the month for the current DateTime instance Int32, 1 to 31 12/9/2018 Wendi Jollymore, ACES
7
DateTime Class Properties: DayOfWeek Month Year
A DayOfWeek enumeration value for the day of the week E.g DayOfWeek.Sunday = 0 Month The month # for the current DateTime instance 1 to 12 Year The year for the current DateTime instance 12/9/2018 Wendi Jollymore, ACES
8
DateTime Class Properties: Now Today
Contains a DateTime object representing the computer’s current date and time Static property Today Like DateTime.Now, but without the time (midnight) 12/9/2018 Wendi Jollymore, ACES
9
DateTime Class Methods: AddDays(int days) AddMonths(int months)
Adds the specified number of days to the current DateTime instance Returns a new DateTime instance AddMonths(int months) As above, but adds specified number of months AddYears(int years) As above, but adds specified number of years 12/9/2018 Wendi Jollymore, ACES
10
DateTime Class Methods: Compare(DateTime d1, DateTime d2)
Static method that takes two DateTime objects and returns Int32 Return value: Is less than 0 d1 is earlier than d2 Is greater than 0 d1 is later than d2 Is 0 d1 and d2 are the same date/time 12/9/2018 Wendi Jollymore, ACES
11
DateTime Class Methods: CompareTo(DateTime d1)
Non-static method compares d1 with current DateTime instance Returns Int32, also: Less than 0 current instance is earlier than d1 Greater than 0 current instance is later than d1 Equal to 0 current instance and d1 are the same 12/9/2018 Wendi Jollymore, ACES
12
DateTime Class Methods: IsLeapYear(int year)
Static method, returns boolean True of year is a leap year False if year isn’t a leap year ToString(), ToShortDateString(), ToLongDateString() Returns various String representations of the current DateTime instance 12/9/2018 Wendi Jollymore, ACES
13
Exercise Add a Calendar control to a new page
Use the AutoFormat item in the task menu to format your calendar You an customize by using the “Styles” category of properties in the Properties window Add code to page load to init the calendar to today’s date: Only if this is the first load i.e. IsPostback == False! 12/9/2018 Wendi Jollymore, ACES
14
Calendar Tutorial Complete the Calendar tutorial in the notes
(ASP.NET/Controls and Events) 12/9/2018 Wendi Jollymore, ACES
15
Validation Controls A set of controls that do client-side validation
Controls are rendered as JavaScript Types of Controls: CompareValidator RangeValidator RegularExpressionValidator RequiredFieldValidator CustomValidator 12/9/2018 Wendi Jollymore, ACES
16
Validation Controls Common Properties: Display ErrorMessage
How the control is displayed on the page Static – error message part takes up space, even when not showing Dynamic – no space taken up by control when no error message None – don’t show error message at all ErrorMessage The error message to display Used by a ValidationSummary control 12/9/2018 Wendi Jollymore, ACES
17
Validation Controls Common Properties: Text ControlToValidate
The text the control will display on the page when there’s an error When this is empty, contents of ErrorMessage property are shown instead ControlToValidate The ID of the control that this validator is validating ValidationGroup Set to a group name if you have multiple groups of controls to validate separately 12/9/2018 Wendi Jollymore, ACES
18
Validation Controls Try it out… set this up: 12/9/2018
Wendi Jollymore, ACES
19
Validation Controls Drag a RequiredFieldValidator to the right of the first text box ID: valReq ControlToValidate: id of first box ErrorMessage: “You must enter an address.” Display: Dynamic Load page and click button without typing address. Add another of these validators for the “confirm ” text box (valReqConfirm) 12/9/2018 Wendi Jollymore, ACES
20
Validation Controls Add a RegularExpressionValidator beside valReq ID: valGood ErrorMessage: “Your address isn’t valid.” ControlToValidate: ID of text box Display: Dyanmic ValidationExpression: Should be set to a regular expression Choose “Internet Address” from the list 12/9/2018 Wendi Jollymore, ACES
21
Validation Controls Add a CompareValidator beside valReqConfirm
ID: val sMatch ErrorMessage: “Your address doesn’t match.” ControlToValidate: ID of confirm text box Display: Dyanmic ControlToCompare: Should be the ID of the control you want to compare to – set to ID of text box ValueToCompare property is used if you want to compare to a static value, instead 12/9/2018 Wendi Jollymore, ACES
22
Exercise Do the Validation exercises in the notes
ASP.NET / Controls and Events 12/9/2018 Wendi Jollymore, ACES
23
Sessions What is a Session? The time a visitor spends on the web site
Starts when they first loads a page Ends when they leave your site, or the session automatically expires Identified by a unique ID stored in a session cookie Cookieless sessions can be used by storing id in the URL You can store information in the Session object A hash table Can store entire objects, not just data Session data is stored on server 12/9/2018 Wendi Jollymore, ACES
24
Sessions You can store data in a session like you would in ViewState:
Session[“userName”] = “Kaluha”; The session variable is called userName The value of the userName variable is “Kaluha” 12/9/2018 Wendi Jollymore, ACES
25
Sessions Tutorial Do the Sessions Tutorial in the notes
ASP.NET / Maintaining State / Sessions Download the images! Set up the page as instructed 12/9/2018 Wendi Jollymore, ACES
26
Sessions Tutorial Repeater control:
Repeats a set of markup/objects You format the templates and it repeats them You bind the control to a data source It will fill the template with your data values The repeater will be linked to a hash table of items and quantities Book title will be key Quantity will be value 12/9/2018 Wendi Jollymore, ACES
27
Sessions Tutorial <ItemTemplate> … </ItemTemplate>
Defines each “row item” in the repeater control Each row in the control will be as defined in the template 12/9/2018 Wendi Jollymore, ACES
28
Sessions Tutorial <asp:Label ID="Label1" width="70" runat="server" text='<%# ... %>'> </asp:Label> <%# %> tags are for inline data binding expressions Single quotes around text attribute value because inline expression requires double-quotes The expression will be evaluated and result will appear in this label’s Text property 12/9/2018 Wendi Jollymore, ACES
29
Sessions Tutorial Container.DataItem DictionaryEntry is a class
((DictionaryEntry)Container.DataItem) Container.DataItem Refers to a specific item of data bound to the current container Current container is the repeater template Data Item will be an element in the hash table DictionaryEntry is a class Models a piece of data with a key/value pair Has a Key property that contains the key portion, and Value property for value Cast DataItem into DictionaryEntry so we can use the Key and Value properties 12/9/2018 Wendi Jollymore, ACES
30
Sessions Tutorial basketList.DataSource = basketTable;
basketList.DataBind(); DataSource property The source of the data that will fill this control Can be a hash table, data set, and other stuff you’ll learn later in the course DataBind() method Gets the data from the data source and populates the control 12/9/2018 Wendi Jollymore, ACES
31
Sessions Tutorial Do the portion of the tutorial that takes you through the code Session[“basket”] = basketTable; Stores a reference to the basketTable hash table in the Session variable basket Page_Prerender() event Executes after control events have been executed, but before HTML is rendered We need the results from the event handler in order to update the repeater Page_Load is too soon, as it executes before the event handler 12/9/2018 Wendi Jollymore, ACES
32
For Next Class.. That last tutorial introduced Data Binding
We’ll look at this in more detail in the next class 12/9/2018 Wendi Jollymore, ACES
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.