Here's the deal: I built a custom validator that should only fire if there is input in the text box. When it fires, it should test to see if the text in the box is an integer, and it will reject it if not. It won't fire, though, and I'm trying to figure out why.
I put this void in the body of the partial c# class:
protected void intValidate_Validate(object sender, ServerValidateEventArgs arg)
{
int num;
bool isNum = int.TryParse(arg.ToString(), out num);
if(arg.Value.Length>0){
if (isNum)
{
arg.IsValid = true;
}
else
{
arg.IsValid = false;
}
}
else{
arg.IsValid=true;
}
}
The code for the validator is as follows:
<div class="adult">
<label>Adults ($10)</label>
<asp:TextBox runat="server" ID="wAdultLunch" class="adultLunch" MaxLength="2" />
<asp:CustomValidator ID="intValidate" ControlToValidate="wAdultLunch" ErrorMessage="Invalid number" OnServerValidate="intValidate_Validate" Display="Static" runat="server" EnableClientScript="False" ValidateEmptyText="True"></asp:CustomValidator>
</div>
Insight would be appreciated!
EDIT: I attached the postback code below
<asp:Button ID="wSubmit" runat="server" Text="Submit" OnClientClick="return validateForm();" causesvalidation="true"/>
<asp:CompareValidator Operator="DataTypeCheck" Type="Integer" ...>and<asp:RangeValidator ...>?ErrorMessageis never displayed?