469,602 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Validator Display Property

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.

Oct 10 '06 #1
2 8260
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

On Oct 9, 8:19 pm, r...@rediffmail.com wrote:
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.
Oct 10 '06 #2
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???
Sean Chambers wrote:
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

On Oct 9, 8:19 pm, r...@rediffmail.com wrote:
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.
Oct 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Arjen | last post: by
1 post views Thread by Stephan Bour | last post: by
6 posts views Thread by darrel | last post: by
1 post views Thread by pathi | last post: by
3 posts views Thread by Tumurbaatar S. | last post: by
2 posts views Thread by Mike Collins | last post: by
reply views Thread by =?Utf-8?B?Tmltcm9kIFJvdG5lcg==?= | last post: by
reply views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.