Before submitting the form I need to test if the sum ( txtA + txtB) is greater than 100. Is it possible to do this with a CustomValidator
, because I don't know if I can choose the 2 textbox in controltovalidate
<asp:TextBox ID="txtA" runat="server"></asp:TextBox>
<asp:TextBox ID="txtB" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2"
runat="server"
ErrorMessage="CustomValidator" />
<asp:Button ID="Button1" runat="server" Text="Button" />
Thanks.
you can do as :
<asp:TextBox ID="txtA" runat="server" />
<asp:TextBox ID="txtB" runat="server" />
<asp:CustomValidator ID="CV1"runat="server"
OnServerValidate="ServerValidation"
ErrorMessage="Sum is less than 100" />
codebehind :
protected void ServerValidation(object source, ServerValidateEventArgs args)
{
args.IsValid = int.Parse(txtA.Text)+ int.Parse(txtB.Text) >100;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With