Date control source code
Last Update:2018-12-07
Source: Internet
Author: User
Source code of a date control! For more information, see!
<Br/> User Control <br/> yearmonthdaydowndroplist. ascx: <br/> <% @ Control Language = "C #" autoeventwireup = "false" <br/> codebehind = "yearmonthdaydowndroplist. ascx. CS "<br/> inherits =" micrm. modules. yearmonthdaydowndroplist "<br/> targetschema =" http://schemas.microsoft.com/intellisense/ie5 "%> <br/> <Table id =" Table1 "cellspacing =" 0 "cellpadding =" 0 "> <br/> tr> <br/> <TD> <select id = <% = yearna Me %> <br/> onclick = <% = javascriptfunname %> <br/> style = "width: 53px; height: 61px "name = <% = yearname %> <br/> <% <br/> filloptions (2000, servernowyear, serveryear ); %> <br/> </SELECT> <br/> <TD> <br/> <div> year </div> <br/> </TD> <br/> <TD> <select id = <% = monthname %> style = "width: 45px; <br/> height: <br/> 61px "onclick = <% = javascriptfunname %> <br/> name = <% = monthname %> <br/> <% <br/> filloptions (, servermo NTH ); %> <br/> </SELECT> <br/> <TD> <br/> <div> month </div> <br/> </TD> <br/> <TD> <select id = <% = dayname %> style = "width: 45px; Height: <br/> 61px "name = <% = dayname %> <br/> <% <br/> filloptions (1, servermonthdays, serverday ); %> <br/> </SELECT> </TD> <br/> <div> day </div> <br/> </TD> <br/> </tr> <br/> </table> </P> <p> In yearmonthdaydowndroplist. ascx. CS: <br/> namespace micrm. modules <br/> {<br/> usin G system; <br/> using system. data; <br/> using system. drawing; <br/> using system. web; <br/> using system. web. UI. webcontrols; <br/> using system. web. UI. htmlcontrols; <br/> /// <summary> <br/> /// Summary of yearmonthdaydowndroplist. <Br/> // </Summary> <br/> public abstract class yearmonthdaydowndroplist: <br/> system. web. UI. usercontrol <br/>{< br/> // select the year, month, and day, for example: 20021225 <br/> Public String yearmonthday <br/>{< br/> Get <br/>{< br/> return <br/> request. form [yearname] + request. form [monthname] + request. form [dayname]; <br/>}< br/> protected int serveryear; // The current server year <br/> protected int servermonth; // server current month <br/> prote CTED int servernowyear; // current server year <br/> protected int serverday; // current server day <br/> protected int servermonthdays; // number of days in the current month <br/> protected string specified criptfunname; // The Name Of The function issued by Control <br/> protected string yearname; // Name Of The Year control issued by the user control <br/> protected string monthname; // name of the month control issued by the user control <br/> protected string dayname; // name of the daily control issued by the user control <br/> private void page_load (Object Sen Der, system. eventargs <br/> E) <br/>{< br/> // place the user <SPAN class = 'wp _ keywordlink '> Code </span> here to initialize the page <br/> string id = this. uniqueid; <br/> If (! This. page. isclientscriptblockregistered (ID) <br/>{< br/> javascriptfunname = "chanday" + ID + "()"; <br/> yearname = "year" + ID; <br/> monthname = "month" + ID; <br/> dayname = "day" + ID; <br/> string scriptstring = "<script language = JavaScript> "; <br/> scriptstring = scriptstring + "function" + javascriptfunname; <br/> scriptstring = scriptstring + "{var days ;"; <br/> scriptstring = scriptstring + "Var currentyear;"; <br/> Scriptstring = scriptstring + "days = 31;"; <br/> scriptstring = scriptstring + "<br/> if(window.doc ument. forms [0]. "+ monthname + ". value = 04 | specified parameter Doc ument. forms [0]. "+ monthname + ". value = 06 | specified parameter Doc ument. forms [0]. "+ monthname + ". value = 09 | too many Doc ument. forms [0]. "+ monthname + ". value = 11) "; <br/> scriptstring = scriptstring +" days = 30; "; <br/> scriptstring = scriptstring +" else <br/> if(window.w.doc ument. forms [0]. "+ monthname + ". value = 02) {"; <br/> scriptstring = scriptstring +" nowyear=w.w.doc ument. forms [0]. "+ yearname + ". value <br/>; "; <br/> scriptstring = scriptstring +" If (nowyear % 4 = 0 <br/> & nowyear % 100! = 0) | nowyear % 400 = 0) "; <br/> scriptstring = scriptstring +" days = 29 ;"; <br/> scriptstring = scriptstring + "else days = 28;"; <br/> scriptstring = scriptstring + "}"; <br/> scriptstring = scriptstring + "<br/> flen1_1_doc ument. forms [0]. "+ dayname + ". length; "; <br/> scriptstring = scriptstring +" <br/> too many Doc ument. forms [0]. "+ dayname + ". length = days; "; <br/> scriptstring = scriptstring +" I = FLEN + 1; "; <br/> SCR Iptstring = scriptstring + "for (I; I <= days; I ++)"; <br/> scriptstring = scriptstring + "{"; <br/> scriptstring = scriptstring + "<br/> too many Doc ument. forms [0]. "+ dayname + ". options (I-1 ). TEXT = I; "; <br/> scriptstring = scriptstring +" <br/> too many Doc ument. forms [0]. "+ dayname + ". options (I-1 ). value = I; "; <br/> scriptstring = scriptstring +"} "; <br/> scriptstring = scriptstring + "}"; <br/> scriptstring = scriptstring + "</SCRIPT> "; <Br/> This. page. registerclientscriptblock (ID, scriptstring); <br/>}< br/> datetime now = datetime. today; <br/> servernowyear = now. year; <br/> If (! Page. ispostback) <br/>{< br/> serveryear = servernowyear; <br/> servermonth = now. month; <br/> serverday = now. day; <br/> servermonthdays = getnowmonthdays (serveryear, servermonth); <br/>}< br/> else <br/>{< br/> serveryear = convert. toint32 (request. form [yearname]); <br/> servermonth = convert. toint32 (request. form [monthname]); <br/> serverday = convert. toint32 (request. form [dayname]); <br/> servermonthdays = Ge Tnowmonthdays (serveryear, servermonth); <br/>}< br/> private int getnowmonthdays (INT serveryear, int <br/> servermonth) <br/>{< br/> int servermonthdays = 31; <br/> If (servermonth = 4 | servermonth = 6 | servermonth = 9 | servermonth = 11) <br/> servermonthdays = 30; <br/> else if (servermonth = 02) <br/> {<br/> If (serveryear % 4 = 0 & serveryear % 100! = 0) | <br/> serveryear % 400 = 0) <br/> servermonthdays = 29; <br/> else servermonthdays = 28; <br/>}< br/> return servermonthdays; <br/>}< br/> protected void filloptions (INT startvalue, int <br/> optionslength, int selectedoption) <br/>{< br/> for (Int J = startvalue; j <= optionslength; j ++) <br/>{< br/> string showoption; <br/> If (j <10) <br/> showoption = "0" + J. tostring (); <br/> else showoption = J. tostring (); <Br/> If (j = selectedoption) <br/> response. write ("<option value =" + showoption + "<br/> selected>" + showoption + "</option>"); <br/> else response. write ("<option value =" + showoption + "<br/>" + showoption + "</option> "); <br/>}< br/> # region web form designer generated code <br/> override protected void oninit (eventargs E) <br/>{< br/> // <br/> // codegen: Asp.. NET web form designer. <Br/> // <br/> initializecomponent (); <br/> base. oninit (E ); <br/>}< br/> // The designer supports the required methods. Do not use the <br/> // code editor to modify the content of this method. <Br/> // </Summary> <br/> private void initializecomponent () <br/>{< br/> This. load + = new system. eventhandler (this. page_load); <br/>}< br/> # endregion <br/>}</P> <p>