R
Radu
Hi. I have an ASP control on my page:
<asp:Calendar
ID="calStart"
................ Etc
</asp:Calendar>
and I have a Custom Validator defined as
<asp:CustomValidator
id="validDate"
Text="*"
ErrorMessage= "The date of the meeting should be at least 7 business
days later than the day of the request !"
Display="Dynamic"
OnServerValidate="ServerValidate" runat="server">
</asp:CustomValidator>
and ServerValidate is defined as:
Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)
Dim objCustomValidator As CustomValidator
Dim objValidationSummary As ValidationSummary
Dim dtChosenDate As Date
objCustomValidator = CType(source, CustomValidator)
objValidationSummary = CType(Me.FindControl("validSummary"),
ValidationSummary)
dtChosenDate =
CType(objCustomValidator.Parent.FindControl("calStart"),
Calendar).SelectedDate
'The date must be greater than today by 7 business days:
If DateDiff(DateInterval.Day, Now, dtChosenDate) < 9 Then
args.IsValid = False
objCustomValidator.IsValid = False
Else
args.IsValid = True
End If
objValidationSummary.Controls.Add(objCustomValidator)
objValidationSummary = Nothing
objCustomValidator = Nothing
End Sub
I also have a ValidationSummary control:
<asp:ValidationSummary
ID="validSummary"
CssClass="MyTextBox"
ShowSummary="false"
ShowMessageBox="true"
DisplayMode="BulletList"
HeaderText="The following data is wrong or missing:"
runat="server"
/>
The validation control works fine with all the others validators on
this page, except this CustomValidator: when I try to leave the page,
if the date is not greater than today by 9, it won't allow me to leave
the page (meaning it's working), but it does not register with the
ValidationSummary control. Where is my problem ?
On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?
Thank you very much.
Alex. Nitulescu
<asp:Calendar
ID="calStart"
................ Etc
</asp:Calendar>
and I have a Custom Validator defined as
<asp:CustomValidator
id="validDate"
Text="*"
ErrorMessage= "The date of the meeting should be at least 7 business
days later than the day of the request !"
Display="Dynamic"
OnServerValidate="ServerValidate" runat="server">
</asp:CustomValidator>
and ServerValidate is defined as:
Protected Sub ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)
Dim objCustomValidator As CustomValidator
Dim objValidationSummary As ValidationSummary
Dim dtChosenDate As Date
objCustomValidator = CType(source, CustomValidator)
objValidationSummary = CType(Me.FindControl("validSummary"),
ValidationSummary)
dtChosenDate =
CType(objCustomValidator.Parent.FindControl("calStart"),
Calendar).SelectedDate
'The date must be greater than today by 7 business days:
If DateDiff(DateInterval.Day, Now, dtChosenDate) < 9 Then
args.IsValid = False
objCustomValidator.IsValid = False
Else
args.IsValid = True
End If
objValidationSummary.Controls.Add(objCustomValidator)
objValidationSummary = Nothing
objCustomValidator = Nothing
End Sub
I also have a ValidationSummary control:
<asp:ValidationSummary
ID="validSummary"
CssClass="MyTextBox"
ShowSummary="false"
ShowMessageBox="true"
DisplayMode="BulletList"
HeaderText="The following data is wrong or missing:"
runat="server"
/>
The validation control works fine with all the others validators on
this page, except this CustomValidator: when I try to leave the page,
if the date is not greater than today by 9, it won't allow me to leave
the page (meaning it's working), but it does not register with the
ValidationSummary control. Where is my problem ?
On a side note - two more questions:
1. When I reset the page (after navigating back and forth), I say in
Page_Load
calStart.SelectedDate = ..... (valid date)
but nothing shows on the screen !
2. can I stop the calendar control from posting back ? Do I have to
write my own javascript-based calendar ?
Thank you very much.
Alex. Nitulescu