I have a user control in some code Ive inherited which allows the user to select a day, month, year from three dropdowns
<%@ Control language="C#" AutoEventWireup="true" inherits="Website.dateDropdown" Codebehind="dateDropdown.ascx.cs" %>
<aspropDownList id="day" runat="server">
</aspropDownList>
<aspropDownList id="month" runat="server">
</aspropDownList>
<aspropDownList id="year" runat="server">
</aspropDownList>
I then populate each dropdown with a blank (meaning nothing selected) followed by the appropriate values (ie day 1 to 31, month jan ... december, 1990 to today)
This all works fine, but there is a requirement for it to be mandatory and for a valid date.
I can add a validator for each field in the control, ie
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server"
ErrorMessage="Enter a day "
ControlToValidate="day"
InitialValue=" ">
</asp:RequiredFieldValidator>
...same for month...same for year
it works, but thats not really what I'm after. Really I just want one error to be displayed if one or more of the fields (day, month, year) are left blank ie 'You must enter a valid date'.
The other problem is a really need this message to be displayed external to the user control, if thats possible as most of the other validations are in the form
<td>field</td><td>Validation message</td>
ie I really want a valdaitor message on a whole uc itself or some way of passing the message out of the user control.
If anyone has any ideas I'd be grateful
Thanks
AndyH1
, but I cannot think how to do this. can anyone suggest a solution
Thanks
AndyH1
<%@ Control language="C#" AutoEventWireup="true" inherits="Website.dateDropdown" Codebehind="dateDropdown.ascx.cs" %>
<aspropDownList id="day" runat="server">
</aspropDownList>
<aspropDownList id="month" runat="server">
</aspropDownList>
<aspropDownList id="year" runat="server">
</aspropDownList>
I then populate each dropdown with a blank (meaning nothing selected) followed by the appropriate values (ie day 1 to 31, month jan ... december, 1990 to today)
This all works fine, but there is a requirement for it to be mandatory and for a valid date.
I can add a validator for each field in the control, ie
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server"
ErrorMessage="Enter a day "
ControlToValidate="day"
InitialValue=" ">
</asp:RequiredFieldValidator>
...same for month...same for year
it works, but thats not really what I'm after. Really I just want one error to be displayed if one or more of the fields (day, month, year) are left blank ie 'You must enter a valid date'.
The other problem is a really need this message to be displayed external to the user control, if thats possible as most of the other validations are in the form
<td>field</td><td>Validation message</td>
ie I really want a valdaitor message on a whole uc itself or some way of passing the message out of the user control.
If anyone has any ideas I'd be grateful
Thanks
AndyH1
, but I cannot think how to do this. can anyone suggest a solution
Thanks
AndyH1