Microsoft
Software
Hardware
Network
Question : How do I combine CustomValidators with RequiredFieldValidators and RegularExpressionValidators?
Hi:
I'm having some issues trying to combine Custom, Required and Regex Validators on an ASP .Net page.
I have a simple text box on a ASP. Net page.
The control currently has Custom Required and REgex validators associated with it.
My validation is not firing as expected.
I would like to:
---------------
1) Test for required field
2) Verify this is a valid numeric entry
3) Perform some special calculations to make sure the value is within a certain threshold.
Step (the custom validator is written in JScript and is included on the page).
I would like all validation to be completed on the client side.
If I remove my custom validator, then Validations 1 & 2 fire as expected.
If I put 3) back, then 1) & 2) do not fire. 3) only fires.
The problem with 3) is that even though it fires and detects invalid conditions, it does not
display the specified error message I've verified that args.IsValid is indeed getting set to false.
The above is true whether I include 1) & 2) or not.
Sample Code is as follows:
=================
<asp:TextBox ID="txtAmount" Visible="true" runat="server" Width="100"
OnTextChanged="onTxtAmount
Changed" AutoPostBack="true"/>
<asp:RequiredFieldValidato
r ID="reqIndividualAmount" runat="server" ControlToValidate="txtAmou
nt" ForeColor=" "
CssClass="error" ErrorMessage="Enter a valid amount" />
<asp:RegularExpressionVali
dator Display="Dynamic" ControlToValidate="txtAmou
nt"
ErrorMessage="Enter a valid amount" ValidationExpression="^\d+
(\.\d(\d)?
)?"
runat="server" ID="reValidator" ForeColor=" " CssClass="error"/>
<asp:CustomValidator ID="cvTxtAmount" runat="server" ControlToValidate="txtAmou
nt"
ErrorMessage="Enter a value less than the maximum." ClientValidationFunction="
validateAm
ount"
OnServerValidate="OnValida
teGLAmount
" ForeColor=" " CssClass="error" />
<script language="javascript" type="text/javascript">
function validateAmount(obj, args) {
args.IsValid = (args.Value != null && args.Value != "");
if (args.IsValid == true) {
try {
/* always forcing to FALSE for testing */
args.IsValid = false;
}
}
catch (e) { }
}
}
</script>
Answer : How do I combine CustomValidators with RequiredFieldValidators and RegularExpressionValidators?
The colour display schemes in XP are reached via the 'Personalization' and are now part of 'Themes'
Random Solutions
Hide vb.net exe from tasklist
Tracking cookies while NOT surfing - yieldmanager.com, atdmt.com, serving-sys.com
how i connect to my camera remotly
What is the impact of recreating an OU certifier on current users?
Windows Server 2008 Creating Folders Issue
VB Script: Output specific text from text file
Active Directory Help
I am trying to compile an already produced program and it gets error 9009, which I was told has to do with the path of the batch program, where do I re-path the batch program correctly?
SBS 2003 R2 remote web workplace
Media Manager in Joomla 1.5.18 will not let me browse or upload