sivakumar
sivakumar

Reputation: 55

ASP.NET Validator Issue when setting Display ="Dynamic"

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.

Upvotes: 3

Views: 13773

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460238

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.

Upvotes: 6

Related Questions