Download - Chapter 6 Slides ASP
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 1
Chapter 6
How to work with server controls
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 2
Objectives
Applied Given the specifications for a web form that uses any of the server
controls presented in this chapter, design and code the form.
Knowledge Describe the normal coding technique for handling control events. Describe the way ASP.NET provides for setting access keys for
controls and for setting the default focus and default button for forms.
Describe the differences between buttons, link buttons, and image buttons.
Describe the use of the e argument when working with an image button control.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 3
Objectives (continued) Describe the use of the Command event and the CommandName
property of a button control for processing a group of button controls.
Describe the differences between the way check box controls and radio button controls work, including the difference in when the CheckedChanged event occurs.
Explain how the items in any of the list controls are stored and how you refer to these items in code.
Explain the purpose of the ListItem Collection Editor and describe when you might use it.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 4
Standard controls Commonly used user input controls such as labels, text boxes, and
drop-down lists Many can be bound to a data source
Data controls Databound user-interface controls that display data via a data
source control Data source controls that access data from a variety of databases,
XML data sources, and business objects
Validation controls Used to validate user input Work by running client-side script Can handle most validation requirements
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 5
Navigation controls Controls that provide menus and path maps for navigating a web
site
Login controls Controls that provide user authentication
WebParts controls Controls that let you create a page from user-selectable
components
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 6
AJAX Extensions controls Controls that provide for updating selected parts of a page during
a postback
HTML controls Standard HTML controls that can be converted to HTML server
controls Not commonly used in ASP.NET applications
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 7
The web server controls presented in this chapter Control Name Suggested prefix
Label lbl TextBox txt Button btn LinkButton lbtn ImageButton ibtn HyperLink hlnk DropDownList ddl ListBox lst
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 8
Web server controls (continued) Control Name Suggested prefix
CheckBox chk CheckBoxList cbl RadioButton rdo RadioButtonList rbl Image img ImageMap imap
BulletedList blst Calendar cln
FileUpload upl
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 9
Handling a Click event using the OnClick attribute The asp tag for a button control <asp:Button id="btnCancel" runat="server" Text="Cancel Order" OnClick="btnCancel_Click">
The event handler for the Click event of the control protected void btnCancel_Click(object sender, EventArgs e) { Session.Remove("Cart"); Response.Redirect("Order.aspx"); }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 10
The asp tags for two button controls that use the same event handler
<asp:Button id="btnPrevious" runat="server" Text="Previous" OnClick="NavigationButtons_Click" /> <asp:Button id="btnNext" runat="server" Text="Next" OnClick="NavigationButtons_Click" />
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 11
Common control events Event Attribute Click OnClick Command OnCommand TextChanged OnTextChanged SelectedIndexChanged OnSelectedIndexChanged CheckedChanged OnCheckedChanged
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 12
A form that uses access keys and default focus and button attributes
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 13
The aspx code for the form <form id="form1" runat="server" defaultfocus="txtName" defaultbutton="btnNext"> <div> Please enter your contact information:<br /><br /> <table> <tr> <td style="width: 75px"> <span style="text-decoration: underline">N</span>ame:</td> <td style="width: 100px"> <asp:TextBox ID="txtName" runat="server" AccessKey="N"></asp:TextBox></td></tr> <tr> <td style="width: 75px"> <span style="text-decoration: underline">E</span>mail:</td> <td style="width: 100px"> <asp:TextBox ID="txtEmail" runat="server" AccessKey="E"> </asp:TextBox></td></tr></table><br />
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 14
The aspx code for the form (continued) <asp:Button ID="btnPrevious" runat="server" AccessKey="P" Text="Previous" OnClick="btnPrevious_Click" /> <asp:Button ID="btnNext" runat="server" AccessKey="N" Text="Next" OnClick="btnNext_Click" /><br /> </div> </form>
A statement that moves the focus to a control txtEmail.Focus
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 15
A button, a link button, and an image button in a browser
The asp tags for the three buttons <asp:Button ID="btnAdd" runat="server" Text="Add to Cart" OnClick="btnAdd_Click" /> <asp:LinkButton ID="lbtnCheckOut" runat="server" PostBackUrl="~/CheckOut1.aspx">Check Out </asp:LinkButton> <asp:ImageButton ID="ibtnCart" runat="server" AlternateText="Cart" ImageUrl="~/Images/cart.gif" Height="60px" Width="68px" PostBackUrl="~/Cart.aspx" />
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 16
Common button attributes Text ImageUrl AlternateText CausesValidation CommandName CommandArgument PostBackUrl
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 17
An event handler for the Click event of a button control protected void btnAccept_Click(object sender, EventArgs e) { this.AddInvoice(); Response.Redirect("Confirmation.aspx"); }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 18
An image used for an image button control
The asp tag for the control <asp:ImageButton ID="ibtnNavigate" runat="server" ImageUrl="~/Images/navbuttons.gif" Height="24px" Width="96px" OnClick="ibtnNavigate_Click" />
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 19
An event handler for the Click event of the control protected void ibtnNavigate_Click(object sender, ImageClickEventArgs e) { if (e.X >= 0 & e.X <= 23) this.GoToFirstRow(); else if (e.X >= 24 & e.X <= 47) this.GoToPreviousRow(); else if (e.X >= 48 & e.X <= 71) this.GoToNextRow(); else if (e.X >= 72 & e.X <= 95) this.GoToLastRow(); }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 20
Properties of the ImageClickEventArgs class Property Description X An integer that represents the x or y coordinate Y where the user clicked the image button.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 21
Four button controls that use the CommandName attribute
<asp:Button ID="btnFirst" runat="server" Text="<<" Width="25px" CommandName="First" OnCommand="NavigationButtons_Command" /> <asp:Button ID="btnPrevious" runat="server" Text="<" Width="25px" CommandName="Previous" OnCommand="NavigationButtons_Command" /> <asp:Button ID="btnNext" runat="server" Text=">" Width="25px" CommandName="Next" OnCommand="NavigationButtons_Command" /> <asp:Button ID="btnLast" runat="server" Text=">>" Width="25px" CommandName="Last" OnCommand="NavigationButtons_Command" />
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 22
An event handler for the Command events of the buttons
protected void NavigationButtons_Command(object sender, CommandEventArgs e) { switch (e.CommandName) { case "First": this.GoToFirstRow(); break; case "Previous": this.GoToPreviousRow(); break; case "Next": this.GoToNextRow(); break; case "Last": this.GoToLastRow(); break; } }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 23
Properties of the CommandEventArgs class Property Description CommandName The value specified in the CommandName
property for the control that generated the Command event.
CommandArgument The value specified in the CommandArgument property for the control that generated the Command event.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 24
A text box and a label displayed in a browser
The asp tag for the text box
<asp:TextBox ID="txtQuestion" runat="server" Rows="5" TextMode="MultiLine" Width="296px"></asp:TextBox>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 25
Common text box attributes TextMode Text MaxLength Wrap ReadOnly Columns Rows
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 26
The asp tag for the label <asp:Label ID="lblConfirm" runat="server"></asp:Label>
Common label attribute Attribute Description Text The text displayed by the label.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 27
Four check boxes and two radio buttons displayed in a browser
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 28
The aspx code for the check boxes and radio buttons
<asp:CheckBox ID="chkMail" runat="server" Checked="True" Text="Add me to your mailing list" /><br /><br /> Contact me about:<br /> <asp:CheckBox ID="chkSpecial" runat="server" Text="Special offers" /><br /> <asp:CheckBox ID="chkNew" runat="server" Text="New products" /><br /> <asp:CheckBox ID="chkRelated" runat="server" Text="Related products" /><br /><br /> Contact me by:<br /> <asp:RadioButton ID="rdoEmail" runat="server" Checked="True" GroupName="Contact" Text="Email" /> <asp:RadioButton ID="rdoPostal" runat="server" GroupName="Contact" Text="Postal mail" />
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 29
Common check box and radio button attributes Attribute Description Text The text that’s displayed next to the check
box or radio button. Checked Indicates whether the check box or radio
button is selected. The default is False. GroupName The name of the group that the control
belongs to (radio buttons only).
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 30
Code that retrieves text entered by a user string question = txtQuestion.Text;
Code that changes the Text property of a label lblConfirm.Text = "Thank you for your question.<br />" + "We will respond within 2 business days.";
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 31
Code that processes a check box and radio button protected void btnContinue_Click(object sender, EventArgs e) { if (chkMail.Checked) customer.Mail = true; else customer.Mail = false; if (rdoEmail.Checked) customer.MailType = "Email"; else customer.MailType = "Postal"; }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 32
Another way to process the check box and radio buttons protected void chkMail_CheckedChanged(object sender, EventArgs e) { if (chkMail.Checked) customer.Mail = true; else customer.Mail = false; } protected void rdoEmail_CheckedChanged(object sender, EventArgs e) { customer.MailType = "Email"; } protected void rdoPostal_CheckedChanged(object sender, EventArgs e) { customer.MailType = "Postal"; }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 33
A list box displayed in a browser
The asp tag for the list box <asp:ListBox ID="lstColor" runat="server"> <asp:ListItem Value="Black" Selected="True">Black</asp:ListItem> <asp:ListItem Value="Red">Red</asp:ListItem> <asp:ListItem Value="Blue">Blue</asp:ListItem> <asp:ListItem Value="Green">Green</asp:ListItem> </asp:ListBox>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 34
A drop-down list displayed in a browser
The asp tag for the drop-down list <asp:DropDownList id="ddlDay" runat="server"> <asp:ListItem Value="1">Sunday</asp:ListItem> <asp:ListItem Value="2">Monday</asp:ListItem> <asp:ListItem Value="3">Tuesday</asp:ListItem> <asp:ListItem Value="4">Wednesday</asp:ListItem> <asp:ListItem Value="5">Thursday</asp:ListItem> <asp:ListItem Value="6">Friday</asp:ListItem> <asp:ListItem Value="7">Saturday</asp:ListItem> </asp:DropDownList>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 35
Common properties of list box and drop-down list controls Items Rows SelectedItem SelectedIndex SelectedValue SelectionMode
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 36
Common properties of list item objects Property Description Text The text that’s displayed for the list item. Value A string value associated with the list item. Selected Indicates whether the item is selected.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 37
Retrieving the value of an item in a drop-down list int dayNumber = Convert.ToInt32(ddlDay.SelectedValue);
Retrieving the text for an item in a drop-down list string dayName = ddlDay.SelectedItem.Text;
Using the SelectedIndexChanged event of a drop-down list protected void ddlDay_SelectedIndexChanged(object sender, EventArgs e) { int dayNumber = Convert.ToInt32(ddlDay.SelectedValue); }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 38
Common property of list item collection objects Count
Common indexer of list item collection objects [index]
Common methods of list item collection objects Add (string) Add (ListItem) Insert (index, string) Insert (index, ListItem) Remove (string)
Remove (ListItem) RemoveAt (index) Clear() FindByValue (string) FindByText (string)
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 39
Code that loads items into a list box using strings lstColor.Items.Add("Black") lstColor.Items.Add("Red") lstColor.Items.Add("Blue") lstColor.Items.Add("Green")
Code that loads items into a drop-down list using ListItem objects
ddlDay.Items.Add(new ListItem("Sunday", "1")) ddlDay.Items.Add(new ListItem("Monday", "2")) ddlDay.Items.Add(new ListItem("Tuesday", "3")) ddlDay.Items.Add(new ListItem("Wednesday", "4")) ddlDay.Items.Add(new ListItem("Thursday", "5")) ddlDay.Items.Add(new ListItem("Friday", "6")) ddlDay.Items.Add(new ListItem("Saturday", "7"))
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 40
The ListItem Collection Editor dialog box
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 41
A check box list and a radio button list displayed in a browser
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 42
The asp tag for the check box list <asp:CheckBoxList id="cblContact" runat="server" Width="305px" RepeatColumns="2"> <asp:ListItem Value="Special"> Special offers</asp:ListItem> <asp:ListItem Value="New"> New products</asp:ListItem> <asp:ListItem Value="Related"> Related products</asp:ListItem> <asp:ListItem Value="Events"> Local events</asp:ListItem> </asp:CheckBoxList>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 43
The asp tag for the radio button list <asp:RadioButtonList id="rblMail" runat="server" Width="346px" RepeatDirection="Horizontal"> <asp:ListItem Value="Email">Email</asp:ListItem> <asp:ListItem Value="Postal"> Postal mail</asp:ListItem> <asp:ListItem Value="Both" Selected="True"> Both</asp:ListItem> </asp:RadioButtonList>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 44
Attributes for formatting radio button and check box lists Attribute Description RepeatLayout Specifies whether ASP.NET should use table
tags (Table) or normal HTML flow (Flow) to format the list when it renders the control. The default is Table.
RepeatDirection Specifies the direction in which the controls should be repeated. The available values are Horizontal and Vertical. The default is Vertical.
RepeatColumns Specifies the number of columns to use when repeating the controls. The default is 0.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 45
A statement that gets the value of the selected item in a radio button list
customer.MailType = rblMail.SelectedValue;
A statement that checks if the first item in a check box list is selected
if (cblContact.Items[0].Selected) ...
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 46
A bulleted list and a numbered list displayed in a browser
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 47
Common attributes of the bulleted list control Attribute Description BulletStyle Specifies the bullet style. For a bulleted list,
allowable values are Disc, Circle, Square, or CustomImage. For a numbered list, allowable values are Numbered, LowerAlpha, UpperAlpha, LowerRoman, or UpperRoman.
BulletImageUrl Specifies the URL of the image used to display the bullets if the BulletStyle attribute is set to CustomImage.
FirstBulletNumber Specifies the starting number if numbers are displayed.
DisplayMode Specifies how the text for each item should be displayed. Allowable values are Text, HyperLink, or LinkButton. Text is the default.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 48
The aspx code for the bulleted list <asp:BulletedList ID="BulletedList1" runat="server" BulletStyle="Disc"> <asp:ListItem>Styrofoam panel</asp:ListItem> <asp:ListItem> Gray and black latex paint</asp:ListItem> <asp:ListItem>Stone texture paint</asp:ListItem> <asp:ListItem>Rotary tool</asp:ListItem> </asp:BulletedList>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 49
The aspx code for the numbered list <asp:BulletedList ID="BulletedList2" runat="server" BulletStyle="Numbered" DisplayMode="HyperLink"> <asp:ListItem Value="Costumes.aspx"> Costumes</asp:ListItem> <asp:ListItem Value="StaticProps.aspx"> Static props</asp:ListItem> <asp:ListItem Value="AnimatedProps.aspx"> Animated props</asp:ListItem> </asp:BulletedList>
A statement that checks if the first link button in a bulleted list was clicked
if (blstCategories.Items[0].Selected) ...
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 50
Some of the Help documentation for the calendar control
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 51
Image control and a hyperlink control in browser
The asp tag for the image control <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Murach logo.jpg" AlternateText="Murach Books" />
Code that sets the URL of an image control imgProduct.ImageUrl = "Images/Products/cat01.jpg";
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 52
Common image attributes Attribute Description ImageUrl The absolute or relative URL of the image. AlternateText The text that’s used in place of the image if the
browser can’t display the image. ImageAlign The alignment of the image relative to the web
page or other elements on the page. Width The width of the image. Height The height of the image.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 53
The asp tag for the hyperlink control <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=http://www.murach.com >Click here to order</ asp:HyperLink>
Common hyperlink attributes Attribute Description NavigateUrl The absolute or relative URL of the page that’s
displayed when the control is clicked. Text The text that’s displayed for the control. ImageUrl The absolute or relative URL of the image that’s
displayed for the control.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 54
A file upload control displayed in a browser
The aspx code used to implement the file upload File upload:<br /><br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /><br /> <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /><br /><br /> <asp:Label ID="lblMessage" runat="server"></asp:Label>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 55
The Click event handler for the Upload button protected void btnUpload_Click(object sender, EventArgs e) { int sizeLimit = 5242880; // 5,242,880 is 5MB if (FileUpload1.HasFile) { if (FileUpload1.PostedFile.ContentLength <= sizeLimit) { string path = "C:\\uploads\\" + FileUpload1.FileName; FileUpload1.SaveAs(path); lblMessage.Text = "File uploaded to " + path; } else lblMessage.Text = "File exceeds size limit."; } }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 56
Properties and methods of the FileUpload class Property Description HasFile If True, the user has selected a file to upload. FileName The name of the file to be uploaded. PostedFile The HttpPostedFile object that represents the
file that was posted. You can use this object’s ContentLength property to determine the size of the posted file.
Method Description SaveAs(string) Saves the posted file to the specified path.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 57
The California.gif image
The aspx code for the image map control <asp:ImageMap ID="imapCA" runat="server" ImageUrl="~/Images/California.GIF" HotSpotMode="PostBack" OnClick="imapCA_Click"> <asp:PolygonHotSpot Coordinates="76, 228, 177, 158, 121, 111, 121, 3, 0, 3, 0, 83, 76, 228" PostBackValue="North" /> <asp:PolygonHotSpot Coordinates="76, 229, 177, 159, 301, 275, 296, 347, 215, 358, 111, 295, 76, 229" PostBackValue="South" /> </asp:ImageMap>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 58
The Click event handler for the image map protected void imapCA_Click(object sender, ImageMapEventArgs e) { string region; if (e.PostBackValue.Equals("North")) region = "NorthernCalifornia"; else region = "SouthernCalifornia"; }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 59
Common image map attributes Attribute Description ImageUrl The URL of the image to be displayed. HotSpotMode Sets the behavior for the hot spots. PostBack
causes the page to be posted and Navigate links to a different page. This attribute can also be specified for individual hot spot elements.
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 60
A web page with an image button that displays a calendar
The web page with the calendar displayed
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 61
The asp tag for the calendar control <asp:Calendar ID="clnArrival" runat="server" Visible="False" OnSelectionChanged="clnArrival_SelectionChanged" BorderColor="Black" BorderStyle="Solid"> <TodayDayStyle BackColor="Blue" Font-Bold="True" ForeColor="White" /> <TitleStyle BackColor="Blue" Font-Bold="True" ForeColor="White" /> <NextPrevStyle ForeColor="White" /> </asp:Calendar>
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 62
The SelectionChanged event handler for the calendar control
protected void clnArrival_SelectionChanged(object sender, EventArgs e) { ddlMonth.SelectedValue = clnArrival.SelectedDate.Month.ToString(); ddlDay.SelectedValue = clnArrival.SelectedDate.Day.ToString(); clnArrival.Visible = false; ibtnCalendar.Visible = true; }
Murach’s ASP.NET 3.5/C#, C6 © 2008, Mike Murach & Associates, Inc. Slide 63
Common properties of the Calendar class Property Description SelectionMode Specifies the type of selection that can be made.
Acceptable values are Day, DayWeek, DayWeekMonth, and None.
SelectedDate The currently selected date if a single date was selected, or the first selected date if multiple dates were selected.
SelectedDates A collection that contains all of the selected dates in sequence. To determine the number of dates that were selected, use the Count property of this collection.