2

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

  1. Click on Button1

  2. RequiredFieldValidator will be shown

  3. Type some text in TextBox

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

1 Answer 1

6

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.

2
  • 1
    Hi Tim, Thanks for the reply. adding a break tag helped. Great to see a valuable reply. Now, I need to try out in the project code something similar, in which I might have some trouble in doing the same
    – sivakumar
    Aug 13, 2010 at 2:42
  • When you can't place a button after the validator, you can use css style min-height to set the size of the table and the button outside the table, it will not moving. :) Aug 4, 2016 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.