I would like to use an <asp:RequiredFieldValidator> to validate a WebDateTimeEdit. Can anyone provide and example of how this is done?
TIA
Hi Ed,
It can be used by exactly same way as for a TextBox. Example:
<igtxt:WebDateTimeEdit ID="WebDateTimeEdit1" runat="server"></igtxt:WebDateTimeEdit><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="WebDateTimeEdit1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
Hi Viktor,
I am trying to use a customvalidator on webdateteimedit control. Basically I need to make the WebDateTimeEdit control required when I check a check box in the form, otherwise I can leave the WebDateTimeEdit control nullable (can be empty). So, I created a custom validator, but its not firing when I have NULLABLE=TRUE.
Can you please help on this?
Regards
SK.
Hi SK,
I created a simple sample from your codes and submit button. Postback did not trigger error message regardless of value in editor.To learn what custom validator does, I looked at generated html and found that dot-net uses following javascript statement:
CustomValidatorDtControl.evaluationfunction = "CustomValidatorEvaluateIsValid";
That function has following content (you can see that in debugger):
function CustomValidatorEvaluateIsValid(val) { var value = ""; if (typeof(val.controltovalidate) == "string") { value = ValidatorGetValue(val.controltovalidate); if ((ValidatorTrim(value).length == 0) && ((typeof(val.validateemptytext) != "string") || (val.validateemptytext != "true"))) { return true; } } var args = { Value:value, IsValid:true }; if (typeof(val.clientvalidationfunction) == "string") { eval(val.clientvalidationfunction + "(val, args) ;"); } return args.IsValid;}
I set a break point in that method and debugger, showed that when editor has no value, then the "value" variable is empty too, but validaton does not fail, because the "val.validateemptytext" is undefined. When I looked at properties of asp:CustomValidator, I found that is has a property with same name. When I set to true ValidateEmptyText, then validation started to work.
I hope that will help you.
Regards,
Viktor
How are you doing? Any update on my issue. Can I use Custom Validator on WebDateTimeEdit in my case? Please let me know.
Thanks
SK
Here is my control definition:
<asp:CheckBox ID="CheckBoxControl" runat="server" Checked ='<%# Bind("CBControlValue") %>'></asp:CheckBox>
<igtxt:WebDateTimeEdit ID="WebDateTimeEditDtControl" Width="80" DataMode="DateOrNull" Value ='<%# Bind("DtValue") %>' runat="server" Nullable="true" ></igtxt:WebDateTimeEdit><asp:CustomValidator ID="CustomValidatorDtControl" runat="server" ErrorMessage="Date is required." Text="*" ControlToValidate="WebDateTimeEditDtControl" OnServerValidate="CustomValidatorDtControl_ServerValidate"></asp:CustomValidator> Protected Sub CustomValidatorDtControl_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Dim CheckBoxControl As CheckBox = CType(FormView1.FindControl("CheckBoxControl"), CheckBox) Dim WebDateTimeEditDtControl As Infragistics.WebUI.WebDataInput.WebDateTimeEdit = CType(FormView1.FindControl("WebDateTimeEditDtControl"), WebDataInput.WebDateTimeEdit) If CheckBoxControl.Checked Then 'Make sure Date entered. If WebDateTimeEditDtControl.Text.Trim = "" Then args.IsValid = False Else args.IsValid = True End If End If
The servervalidate event fires only if I have a value in the WebDateTimeEdit control or if I have Nullable="false".
Thanks for helping on this.
-SK
Can you provide a simple sample for that?
If codes are larger than a page or 2, then you may zip files and attach it within Options tab.