J
John Bonds
I'm having some problems with implementing client-side validation in a user
control. Here' my code for the usercontrol:
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="uclPayment.ascx.vb" Inherits="maestroglass.uclPayment"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<script language="vbscript">
Sub ValidateExpirationDate(source, args)
'MsgBox(document.forms)
Dim pFormDate As Date = DateValue("1/" &
ddlExpirationMonth.SelectedItem.Value & "/" &
ddlExpirationYear.SelectedItem.Value)
If DateDiff("M", Now, pFormDate) >= 0 Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
</script>
<TABLE id="htbLayout" style="BORDER-RIGHT: thin outset; BORDER-TOP: thin
outset; BORDER-LEFT: thin outset; BORDER-BOTTOM: thin outset"
cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<TD width="150">Payment Method</TD>
<TD>Credit Card No.</TD>
<TD width="200">Expiration Date</TD>
</TR>
<TR>
<TD><asp:dropdownlist id="ddlCreditCardType" runat="server">
<asp:ListItem Value="VISA" Selected="True">VISA</asp:ListItem>
<asp:ListItem Value="Master Card">Master Card</asp:ListItem>
<asp:ListItem Value="American Express">American Express</asp:ListItem>
<asp:ListItem Value="Discover">Discover</asp:ListItem>
</asp:dropdownlist></TD>
<TD><asp:textbox id="tbxCreditCardNum" runat="server"
Width="200px"></asp:textbox><asp:requiredfieldvalidator
id="reqCreditCardNum" runat="server" ErrorMessage="Please enter a credit
card number"
ControlToValidate="tbxCreditCardNum"></asp:requiredfieldvalidator><asp:custo
mvalidator id="cuvCreditCardNum" runat="server" ErrorMessage="Credit Card
number is invalid"
ControlToValidate="tbxCreditCardNum"></asp:customvalidator></TD>
<TD><asp:dropdownlist id="ddlExpirationMonth" runat="server">
<asp:ListItem Value="1" Selected="True">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
<asp:ListItem Value="11">11</asp:ListItem>
<asp:ListItem Value="12">12</asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id="ddlExpirationYear"
runat="server"></asp:dropdownlist><asp:customvalidator id="cuvExpiration"
runat="server" ErrorMessage="Expiration is invalid"
</TR>
</TABLE>
Thanks
control. Here' my code for the usercontrol:
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="uclPayment.ascx.vb" Inherits="maestroglass.uclPayment"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<script language="vbscript">
Sub ValidateExpirationDate(source, args)
'MsgBox(document.forms)
Dim pFormDate As Date = DateValue("1/" &
ddlExpirationMonth.SelectedItem.Value & "/" &
ddlExpirationYear.SelectedItem.Value)
If DateDiff("M", Now, pFormDate) >= 0 Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
</script>
<TABLE id="htbLayout" style="BORDER-RIGHT: thin outset; BORDER-TOP: thin
outset; BORDER-LEFT: thin outset; BORDER-BOTTOM: thin outset"
cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<TD width="150">Payment Method</TD>
<TD>Credit Card No.</TD>
<TD width="200">Expiration Date</TD>
</TR>
<TR>
<TD><asp:dropdownlist id="ddlCreditCardType" runat="server">
<asp:ListItem Value="VISA" Selected="True">VISA</asp:ListItem>
<asp:ListItem Value="Master Card">Master Card</asp:ListItem>
<asp:ListItem Value="American Express">American Express</asp:ListItem>
<asp:ListItem Value="Discover">Discover</asp:ListItem>
</asp:dropdownlist></TD>
<TD><asp:textbox id="tbxCreditCardNum" runat="server"
Width="200px"></asp:textbox><asp:requiredfieldvalidator
id="reqCreditCardNum" runat="server" ErrorMessage="Please enter a credit
card number"
ControlToValidate="tbxCreditCardNum"></asp:requiredfieldvalidator><asp:custo
mvalidator id="cuvCreditCardNum" runat="server" ErrorMessage="Credit Card
number is invalid"
ControlToValidate="tbxCreditCardNum"></asp:customvalidator></TD>
<TD><asp:dropdownlist id="ddlExpirationMonth" runat="server">
<asp:ListItem Value="1" Selected="True">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
<asp:ListItem Value="11">11</asp:ListItem>
<asp:ListItem Value="12">12</asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id="ddlExpirationYear"
runat="server"></asp:dropdownlist><asp:customvalidator id="cuvExpiration"
runat="server" ErrorMessage="Expiration is invalid"
</TR>
</TABLE>
Thanks