| | |
Disabling dates before current date of a datetimepicker control
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2007
Posts: 276
Reputation:
Solved Threads: 37
I'm not certain what version of Visual Studio you're using - I'm still using 2003 however we have purchased and installed 2008 and I am preparing to start using it in the next week or two..
however in 2003 in your toolbox you have the required field validator you can use - you set the validator to validate the date textbox or whatever you want and in the operator field of the properties you chose greater than or greater than equal if you want them to be able to enter todays date.
you can then insert a validation summary from the toolbox and in error message of your validator you can list the message you want to place in that summary area. So you can say "Date can not be prior to today" and it will tell them what's wrong. You can even insert a second validator and make it required so it will make sure it's also not blank and so on.
you can mess with settings like make the color red etc.
Then in your code you can put in a valid fields check - an example I've used for one of mine is here
in the above example - rqvDueDate is one validator that was inserted to validate due date. That name was set in the id field of the properties.
however in 2003 in your toolbox you have the required field validator you can use - you set the validator to validate the date textbox or whatever you want and in the operator field of the properties you chose greater than or greater than equal if you want them to be able to enter todays date.
you can then insert a validation summary from the toolbox and in error message of your validator you can list the message you want to place in that summary area. So you can say "Date can not be prior to today" and it will tell them what's wrong. You can even insert a second validator and make it required so it will make sure it's also not blank and so on.
you can mess with settings like make the color red etc.
Then in your code you can put in a valid fields check - an example I've used for one of mine is here
VB.NET Syntax (Toggle Plain Text)
Private Sub ValidFields() Dim strError As String = "Validating Request." Try cpvRequestedDueDate.ValueToCompare = DateTime.Now.Today.ToShortDateString rfvReqUser.Validate() rfvTitle.Validate() rfvDescription.Validate() rfvPriority.Validate() cpvRequestedDueDate.Validate() cpvRequestedDueDate2.Validate() rqvDueDate.Validate() Catch ex As SqlException PageUtil.ShortProcessErrors(ex, Session, Me, strError) PageUtil.ShowError(Page, strError) Catch ex As Exception PageUtil.ShortProcessErrors(ex, Session, Me, strError) PageUtil.ShowError(Page, strError) Finally End Try End Sub
in the above example - rqvDueDate is one validator that was inserted to validate due date. That name was set in the id field of the properties.
Last edited by rapture; Oct 9th, 2008 at 12:37 pm.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Keypress event
- Next Thread: Hotel Occupancy formHelp
Views: 2281 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code combobox component convert crystalreport data database databasesearch datagrid datagridview design designer dissertation dissertations dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy highlighting images inline insert installer intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project save searchbox searchvb.net select serial server soap sorting studio syntax table tcp text textbox time timer toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





