DatePicker (Date Select Custom server control) implementation
Source: Internet
Author: User
Server | control | Date selection has user-defined controls (. ascx) and server controls (program code) in dotnet
The WebControl class provides common properties, methods, and events for all WEB server controls. You can control the appearance and behavior of Web server controls by setting properties defined in this class.
For example, the implementation of DatePicker controls in community
public class Datepicker:webcontrol, INamingContainer {
DropDownList Dropmonth;
DropDownList Dropday;
DropDownList dropyear;
public int Month {
get {
if (viewstate["Month"] = = null)
return DateTime.Now.Month;
Else
return (int) viewstate["Month"];
}
set {viewstate["Month"] = value;}
}
public int Day {
get {
if (viewstate["day"] = = null)
return DateTime.Now.Day;
Else
return (int) viewstate[' Day '];
}
set {viewstate["day"] = value;}
}
public int Year {
get {
if (viewstate["year"] = = null)
return DateTime.Now.Year;
Else
return (int) viewstate["year"];
}
set {
viewstate["Year"] = value;
}
}
Public DateTime Date {
get {
Determines whether the server control contains child controls. If not, the child control is created.
EnsureChildControls ();
int _year = Int32.Parse (DropYear.SelectedItem.Value);
int _month = Int32.Parse (DropMonth.SelectedItem.Value);
int _day = Int32.Parse (DropDay.SelectedItem.Value);
if (_day > Datetime.daysinmonth (_year, _month))
throw new ArgumentException ("Invalid date!");
return new DateTime
(
_year,
_month,
_day
);
}
set {
Month = value. Month;
Day = value. Day;
Year = value. year;
}
}
<summary>
Notifies you to create any child controls that they contain by using a composite implementation-based server control to prepare for postback or rendering.
You must override this method when you are developing a composite server control or a template server control.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service