Validator Display Property

R

rn5a

The different Validation controls like RequiredFieldValidator,
RangeValidator etc. have a property named Display. This property can
have 3 values - Dynamic, Static & None. What's the difference between
the Dynamic Display & Static Display?

Also suppose a Form has 2 TextBoxes & both the TextBoxes have the
RequiredFieldValidator. The Form has a Button as well.

<form runat="server">
First Name: <asp:TextBox ID="txtFName" runat="server"/>
<asp:RequiredFieldValidator ID="reqFName" ControlToValidate="txtFName"
Display="static" ErrorMessage="Please Enter Your First Name"
runat="server"/><br>
Last Name: <asp:TextBox ID="txtLName" runat="server"/>
<asp:RequiredFieldValidator ID="reqLName" ControlToValidate="txtLName"
Display="static" ErrorMessage="Please Enter Your Last Name"
runat="server"/><br>
<asp:Button ID="btn" OnClick="SubmitClick" Text="SUBMIT"
runat="server"/>
</form>

Assume that the cursor is in the txtFName TextBox i.e. txtFName has the
focus. Without typing anything in the txtFName TextBox, I set the focus
to the txtLName TextBox. When I do this, the RequiredFieldValidator
gets into the act & immediately displays the ErrorMessage since the
txtFName TextBox is empty.

Now how do I ensure that the RequiredFieldValidator gets into the act &
displays the ErrorMessage (if any or both the TextBoxes are empty) only
when the user clicks the Submit Button?

I don't want the RequiredFieldValidator to display the ErrorMessage as
soon as an empty TextBox loses focus; rather the ErrorMessage should be
displayed only when the Submit Button is clicked & ASP.NET finds that
one (or any) of the TextBoxes is empty.
 
S

Sean Chambers

I haven't looked at the actual client side script that the validation
controls use (lazy at the moment)

I am assuming that their client side validation fires a javascript
function each time a field is unfocused, or each time a field is
focused (probably the latter), in turn, it probably checks all the
validation controls for empty values which is the results you are
seeing.

At first glance, you could just set the "EnableClientScript" to false
for each of the validators, and then processing for errors would occur
at the server after the postback occurs.

There may be an easier way though, but that's what I would probably do.
I would be interested to see what other ways you can accomplish this,
probably something very simple =)

hope this helps!

Sean
 
R

rn5a

No, my dear friend Sean, setting EnableClientScript to False doesn't
resolve the issue. Leave alone suppressng the ErrorMessage when a user
moves from one control to another (assuming that the first control
doesn't have valid data), the Validation Controls don't even fire when
the Form is submitted. In other words, the Form gets submitted without
any validation just because of the presence of EnableClientScript=False
in the validator!

Please try it out on your m/c. & let me know whether you experience the
same result or not.

Any other ideas???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top