Netadvantage Asp.net -- use webdatechooser to verify the start date and end date on the client

Source: Internet
Author: User
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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.