peachsoda03
07-22-2008, 11:03 PM
Hello all,
Just a quick forewarning... I am a complete newbie to asp.net. I code regularly in Coldfusion, but every now and then I my job will require me to use asp.net, and now is such a case. I'm finding that things I can do easily in CF are taking me hours in asp.net, such as this validation problem that I seem unable to solve.
I'm working on a simple web form that asks for basic information (name, address, etc). At the end of the form, it asks you to select one of two options on a RadioButtonList:
What are you moving?
<asp:RadioButtonList ID="whatMove" runat="server">
<asp:ListItem Value="wholeHouse"> Whole house: </asp:ListItem>
<asp:ListItem Value="fewRooms"> Just a few rooms: </asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="whatMove" ErrorMessage="Please select a move option."></asp:RequiredFieldValidator>
I've figured out the RequiredFieldValidator (which is surprisingly easy to use), which you can see above. However, depending on which option the user selects, I need to add additional validation.
If the user selects "Whole house" as an option, then they need to be forced to select an option from a drop down list:
<asp:DropDownList ID="whatMoveHouse" runat="server">
<asp:ListItem Value="-1">- Select an option -</asp:ListItem>
<asp:ListItem Value="1 bedroom house">1 bedroom house</asp:ListItem>
<asp:ListItem Value="2 bedroom house">2 bedroom house</asp:ListItem>
<asp:ListItem Value="3 bedroom house">3 bedroom house</asp:ListItem>
<asp:ListItem Value="4 bedroom house">4 bedroom house</asp:ListItem>
<asp:ListItem Value="5 bedroom house">5 bedroom house</asp:ListItem>
<asp:ListItem Value="6 bedroom house">6 bedroom house</asp:ListItem>
<asp:ListItem Value="Studio apartment">Studio apartment</asp:ListItem>
<asp:ListItem Value="1 bedroom apartment">1 bedroom apartment</asp:ListItem>
<asp:ListItem Value="2 bedroom apartment">2 bedroom apartment</asp:ListItem>
<asp:ListItem Value="3 bedroom apartment">3 bedroom apartment</asp:ListItem>
</asp:DropDownList>
If the user selected "Just a few rooms" from the list, then they need to be required to select at least one option in a CheckBoxList:
<asp:CheckBoxList ID="whatMoveRoom" runat="server" style="padding-left: 20px;">
<asp:ListItem Value="Kitchen"> Kitchen</asp:ListItem>
<asp:ListItem Value="Bedroom"> Bedroom</asp:ListItem>
<asp:ListItem Value="Family room"> Family room</asp:ListItem>
<asp:ListItem Value="Dining room"> Dining room</asp:ListItem>
<asp:ListItem Value="Bathroom"> Bathroom</asp:ListItem>
</asp:CheckBoxList>
From what I've read, using a CustomValidator is the way to go, which I've tried adding to the CheckBoxList:
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select at least one room type." ControlToValidate="whatMove"></asp:CustomValidator>
However, from this point on, I am lost. I have been messing with some for-loops and such but am unsure exactly what sort of checks I need to do. This is what I have so far:
Public Sub whatMoveRoomCheck(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
For Each l As ListItem In whatMoveRoom.Items
If (l.Selected) Then
args.IsValid = True
Return
End If
Next
args.IsValid = False
End Sub
I am at my wit's end about this (it would have taken me a mere 10 minutes using html forms and javascript), and I've already put a good 6-7 hours into researching and testing things. No luck yet. Any help is greatly and very much appreciated. :)
Jennifer
Just a quick forewarning... I am a complete newbie to asp.net. I code regularly in Coldfusion, but every now and then I my job will require me to use asp.net, and now is such a case. I'm finding that things I can do easily in CF are taking me hours in asp.net, such as this validation problem that I seem unable to solve.
I'm working on a simple web form that asks for basic information (name, address, etc). At the end of the form, it asks you to select one of two options on a RadioButtonList:
What are you moving?
<asp:RadioButtonList ID="whatMove" runat="server">
<asp:ListItem Value="wholeHouse"> Whole house: </asp:ListItem>
<asp:ListItem Value="fewRooms"> Just a few rooms: </asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="whatMove" ErrorMessage="Please select a move option."></asp:RequiredFieldValidator>
I've figured out the RequiredFieldValidator (which is surprisingly easy to use), which you can see above. However, depending on which option the user selects, I need to add additional validation.
If the user selects "Whole house" as an option, then they need to be forced to select an option from a drop down list:
<asp:DropDownList ID="whatMoveHouse" runat="server">
<asp:ListItem Value="-1">- Select an option -</asp:ListItem>
<asp:ListItem Value="1 bedroom house">1 bedroom house</asp:ListItem>
<asp:ListItem Value="2 bedroom house">2 bedroom house</asp:ListItem>
<asp:ListItem Value="3 bedroom house">3 bedroom house</asp:ListItem>
<asp:ListItem Value="4 bedroom house">4 bedroom house</asp:ListItem>
<asp:ListItem Value="5 bedroom house">5 bedroom house</asp:ListItem>
<asp:ListItem Value="6 bedroom house">6 bedroom house</asp:ListItem>
<asp:ListItem Value="Studio apartment">Studio apartment</asp:ListItem>
<asp:ListItem Value="1 bedroom apartment">1 bedroom apartment</asp:ListItem>
<asp:ListItem Value="2 bedroom apartment">2 bedroom apartment</asp:ListItem>
<asp:ListItem Value="3 bedroom apartment">3 bedroom apartment</asp:ListItem>
</asp:DropDownList>
If the user selected "Just a few rooms" from the list, then they need to be required to select at least one option in a CheckBoxList:
<asp:CheckBoxList ID="whatMoveRoom" runat="server" style="padding-left: 20px;">
<asp:ListItem Value="Kitchen"> Kitchen</asp:ListItem>
<asp:ListItem Value="Bedroom"> Bedroom</asp:ListItem>
<asp:ListItem Value="Family room"> Family room</asp:ListItem>
<asp:ListItem Value="Dining room"> Dining room</asp:ListItem>
<asp:ListItem Value="Bathroom"> Bathroom</asp:ListItem>
</asp:CheckBoxList>
From what I've read, using a CustomValidator is the way to go, which I've tried adding to the CheckBoxList:
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select at least one room type." ControlToValidate="whatMove"></asp:CustomValidator>
However, from this point on, I am lost. I have been messing with some for-loops and such but am unsure exactly what sort of checks I need to do. This is what I have so far:
Public Sub whatMoveRoomCheck(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
For Each l As ListItem In whatMoveRoom.Items
If (l.Selected) Then
args.IsValid = True
Return
End If
Next
args.IsValid = False
End Sub
I am at my wit's end about this (it would have taken me a mere 10 minutes using html forms and javascript), and I've already put a good 6-7 hours into researching and testing things. No luck yet. Any help is greatly and very much appreciated. :)
Jennifer