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.
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.