By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Validator Display Property

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.