Jump to content

Using validation controls


cothedo

Recommended Posts

I have a form with asp:RadioButtons where I need to perform validation before the form is submitted. How do you use a validation where you first check if the radiobutton is checked (for example: UploadImageRadioButton), and, if so, check if a asp:FileUpload (ImageUpload) control has a value: <tr> <td style="text-align: right;" rowspan="2">Images:</td> <td><asp:RadioButton GroupName="ImageSelect" ID="UploadImageRadioButton" runat="server" /> <asp:FileUpload ID="ImageUpload" Width="250" runat="server" /></td> </tr> <tr> <td><asp:RadioButton GroupName="ImageSelect" Text="" ID="SelecetImageRadioButton" runat="server" /> <asp:DropDownList ID="ImagesDropDownList" runat="server"> </asp:DropDownList> </td> </tr>

Link to comment
Share on other sites

I have a form with asp:RadioButtons where I need to perform validation before the form is submitted. How do you use a validation where you first check if the radiobutton is checked (for example: UploadImageRadioButton), and, if so, check if a asp:FileUpload (ImageUpload) control has a value: <tr> <td style="text-align: right;" rowspan="2">Images:</td> <td><asp:RadioButton GroupName="ImageSelect" ID="UploadImageRadioButton" runat="server" /> <asp:FileUpload ID="ImageUpload" Width="250" runat="server" /></td> </tr> <tr> <td><asp:RadioButton GroupName="ImageSelect" Text="" ID="SelecetImageRadioButton" runat="server" /> <asp:DropDownList ID="ImagesDropDownList" runat="server"> </asp:DropDownList> </td> </tr>
Never mind, I already found a solution to my problem using the customvalidator control. This article by Scott Mitchell was really helpful: http://aspnet.4guysfromrolla.com/articles/073102-1.aspx
Link to comment
Share on other sites

Never mind, I already found a solution to my problem using the customvalidator control. This article by Scott Mitchell was really helpful: http://aspnet.4guysfromrolla.com/articles/073102-1.aspx
That's very strange you should ask that as i am currently looking at the same kind of thing.I am using a asp:checkboxlist and wanted to use the 'requiredfieldvalidator' but i remember reading that t doesn't support this. Therefore i think i will use this so called customvalidator too. :)
Link to comment
Share on other sites

That's very strange you should ask that as i am currently looking at the same kind of thing.I am using a asp:checkboxlist and wanted to use the 'requiredfieldvalidator' but i remember reading that t doesn't support this. Therefore i think i will use this so called customvalidator too. :)
I don't believe checkbox's are supported at all with validation controls in asp.net. However i am creating my own validation anyway but it is always nice to know. :)
Link to comment
Share on other sites

I don't believe checkbox's are supported at all with validation controls in asp.net. However i am creating my own validation anyway but it is always nice to know. :)
No, checkboxes are not supported by validation controls, but there's a way around that:<asp:RadioButton GroupName="ImageSelect" ID="UploadImageRadioButton" runat="server" /><asp:FileUpload ID="ImageUpload" Width="250" runat="server" /><asp:CustomValidator ID="CheckFileUpload" runat="server" ControlToValidate="ImageUpload" ClientValidationFunction="CheckFileUploadValue" ValidateEmptyText="true" ErrorMessage="Select a file"></asp:CustomValidator>I wanted to check if a file has been selected with the asp:FileUpload if the radiobutton was selected. I used the custom validator to check the asp:FileUpload (see if it had a value), but also if the radiobutton was checked, like so:Protected Sub CheckFileUpload_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CheckFileUpload.ServerValidate If args.Value = "" And UploadImageRadioButton.Checked = True Then args.IsValid = False Else args.IsValid = True End If End SubI used a similar construction for the client-side validation of the customvalidator.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...