Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
ASP.NET Validation Question
Old 02-14-2005, 01:31 AM ASP.NET Validation Question
Novice Talker

Posts: 11
Trades: 0
I have a web form using asp controls.
I am implementing validation into the form.
I've run into a little snag I can't seem to get past.

Here's the code:
Code:
<asp:RadioButton ID="CC" Text="Credit Card" GroupName="PayMethod" runat="server" />
<asp:RadioButton ID="Check" Text="Check/Money Order" GroupName="PayMethod" runat="server" />

<asp:DropDownList ID="CardType" runat="server">
     <asp:ListItem Value="" Selected="true"></asp:ListItem>
     <asp:ListItem Value="Visa">Visa</asp:ListItem>
     <asp:ListItem Value="MC">MasterCard</asp:ListItem>
     <asp:ListItem Value="Amex">American Express</asp:ListItem>
     <asp:ListItem Value="Disc">Discover</asp:ListItem>
</asp:DropDownList>
What I want is if the Credit Card radiobutton is selected then the CardType dropdown must be validated. If the Check/Money Order radiobutton is selected, the dropdown will remain blank and I don't want to validate it.

I tried this right below the dropdown list:
Code:
<% If CC.checked = "True" then %>
     <asp:RequiredFieldValidator ID="CardTypeRequired" ControlToValidate="CardType" runat="server" ErrorMessage="Credit Card Type">***</asp:RequiredFieldValidator>
<% End If %>
But the Validator runs whether CC.checked is true or false.
Not sure how to put the IF-THEN where it will work.
Any help is appreciated.
Thanks

-Tom
bowfonz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-14-2005, 10:28 AM
ACW
Average Talker

Posts: 26
Trades: 0
This works fine for me...
Code:
<form id="Form1" method="post" runat="server">
		<asp:RadioButton ID="CC" Text="Credit Card" GroupName="PayMethod" runat="server" />
		<asp:RadioButton ID="Check" Text="Check/Money Order" GroupName="PayMethod" runat="server" />
		<asp:DropDownList ID="CardType" runat="server">
			<asp:ListItem Value="" Selected="true"></asp:ListItem>
			<asp:ListItem Value="Visa">Visa</asp:ListItem>
			<asp:ListItem Value="MC">MasterCard</asp:ListItem>
			<asp:ListItem Value="Amex">American Express</asp:ListItem>
			<asp:ListItem Value="Disc">Discover</asp:ListItem>
		</asp:DropDownList>
		<% If CC.checked = "True" then %>
			<asp:RequiredFieldValidator ID="CardTypeRequired" ControlToValidate="CardType" runat="server" ErrorMessage="Credit Card Type">***</asp:RequiredFieldValidator>
		<% End If %>
		<br>
		<INPUT type="submit" value="Submit">
</form>
__________________

Please login or register to view this content. Registration is FREE
by Geo Redundant Hosting
ACW is offline
Reply With Quote
View Public Profile
 
Old 02-15-2005, 03:40 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Instead of having code in the body of your document, you could use:
Code:
<asp:CustomValidator id="cvCCard" runat="server" ControlToValidate="CardType" ErrorMessage="Credit Card Type" OnServerValidate="cvCard_Validate">***</asp:CustomValidator>
Then in the <script> tags,
Code:
Sub cvCCard_Validate(source As Object, args As ServerValidateEventArgs)
    If CC.Checked Then
        If args.Value = String.Empty Then args.IsValid = False Else IsValid = True
    End If
End Sub
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 02-18-2005, 11:28 AM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
There is a nice Creditcard validator at ASPEmporium.com
Try there.

Hope that helps.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to ASP.NET Validation Question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13656 seconds with 12 queries