For date selection, we often use the webdatechooser control. When it comes to the start date and end date, we need to verify the validity of the date, which is often encountered during development, therefore, we can write a common method to verify the validity of the date on the client, instead of waiting for the submission to the server for verification. The method is as follows:
Public void bindcomparedatechoosers (control usercontrol, infragistics. webui. webschedule. webdatechooser begindatechooser, infragistics. webui. webschedule. webdatechooser enddatechooser)
...{
String comparejs = "<script language = JavaScript>" +
"Function comparedate (ocalendar, newvalue, oevent)" +
"{" +
"Var datechooserbegin = igdrp_getcombobyid ('" + begindatechooser. clientid + "');" +
"Var datechooserend = igdrp_getcombobyid ('" + enddatechooser. clientid + "');" +
"If (ocalendar = datechooserbegin. calendar)" +
"{" +
"Var datebegin = newvalue;" +
"Var dateend = datechooserend. getvalue ();" +
"Var dateendtext = datechooserend. gettext ();" +
"If (dateendtext! = '--- Select ---' & dateendtext! = ''& Datebegin> dateend)" +
"{" +
"Alert ('when selecting a date range, the start date cannot be later than the end date! '); "+
"Oevent. Cancel = true;" +
"}" +
"}" +
"If (ocalendar = datechooserend. calendar)" +
"{" +
"Var datebegin = datechooserbegin. getvalue ();" +
"Var dateend = newvalue;" +
"Var datebegintext = datechooserbegin. gettext ();" +
"If (datebegintext! = '--- Select ---' & datebegintext! = ''& Datebegin> dateend)" +
"{" +
"Alert ('when selecting a date range, the start date cannot be later than the end date! '); "+
"Oevent. Cancel = true;" +
"}" +
"}" +
"}" +
"</SCRIPT> ";
Usercontrol. Page. clientscript. registerstartupscript (usercontrol. GetType (), "comparedate", comparejs );
Begindatechooser. clientsideevents. calendarvaluechanging = "comparedate ";
Enddatechooser. clientsideevents. calendarvaluechanging = "comparedate ";
}
We can directly call bindcomparedatechoosers (this, begindatechooser, enddatechooser) on the page or the page_load function of the control to bind the verification date script.
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1534780