Here is my ASP.NET code. Simple. it has a A textbox associated with a required field validator and a submit button.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Click Me" />
Do the following
Click on Button1
RequiredFieldValidator will be shown
Type some text in TextBox
Use your Mouse(no tab please). and click on the button , you can see that your page does not "POSTBACK" and only the validation gets cleared. you need to
click again the button for Submission of Form.
This seems to be a bug by Microsoft when setting the property Display ="Dynmaic" and Is there a easy workaround without changing the intended behavior for
this available? I couldn't find a solution for this anywhere.
Your page does not submit because the button moves away under the mouse when you want to click it. This is because it gets focus and the Validator-ErrorMessage disappears to the left.
If you insert a <br/> in front of the button it works.
Normally i use * as Text and use a ValidationSummary to display the ErrorMessage(s):
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
ErrorMessage="This is the Errormessage" Text="*"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
Or, if using ASP.Net Ajax, you could use nifty controls like the ValidatorCalloutExtender.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With