Article ID: 310082 - Last Review: December 6, 2006 - Revision: 3.5 How to extend a Web Form control to work with the validation controls by using Visual Basic .NET or Visual Basic 2005This article was previously published under Q310082 On This PageSUMMARY You cannot use all Web Form controls in conjunction with
the validator controls. To use controls with the validation controls, the
control must have a ValidationProperty attribute. The ValidationProperty attribute specifies against which value the validation controls
should validate. This article demonstrates how extend a Web Form control to
work with the validation controls. The Calendar control is one of the controls that cannot be validated in its original state. In many cases, however, you must be able to validate the user selection in the Calendar control. There are two solutions to this problem:
NOTE: This article demonstrates how to extend the Calendar control for server-side validation only. For client-side validation to occur, the validation controls hook up to the corresponding HTML control's Value property. Because many HTML controls are used to build the Calendar control, no single HTML control contains the selected value for the Calendar control. Thus, client-side validation is not appropriate for the Calendar control. Extend the Calendar ControlTo extend the Calendar control, you can create a class that inherits from the existing Calendar control. To allow the control to interact with the validation controls, you add the ValidationProperty attribute and a property that returns the selected date in a format that is suitable for the validation controls.To allow the control to be used with the RequiredFieldValidator control, you return an empty string if the SelectedDate property of the Calendar control is set to "01-Jan-0001" because "01-Jan-0001" is the date that is returned if no date is selected. In all other cases, you return a string that contains the date in the yyyy/MM/dd format that the RangeValidator control can use.
Add the Control to a Web FormTo add a custom control to a Web Form, you must add a reference to the top of the Web page. This defines the namespace and tag that you use in the HTML.
Link to Validator ControlsThe sample code in this section demonstrates how to add a RangeValidator and RequiredFieldValidator control to the Web Form and how to link them to the VCalendar control.
Test the Web Page
REFERENCES For more information, refer to the "Web Forms Validation"
topic in the Microsoft Visual Studio .NET Online Help documentation. This topic
contains links to other Web Form validation topics. To search for this topic,
type Web Forms Validation in the help documentation
search feature, and limit the search to Titles Only. | Article Translations
|
Back to the top
