本文介绍了ASP.NET验证设置问题时显示= QUOT;动态"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的ASP.NET code。简单。它有一个必填字段校验器和一个提交按钮相关的一个文本框。

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" />

执行以下操作


  1. 点击Button1的

  1. Click on Button1

的RequiredFieldValidator将显示

RequiredFieldValidator will be shown

在文本框中一些文本

使用鼠标(没有选项卡,请)。并点击按钮,就可以看到你的页面不回传,只有验证被清除。你需要

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.

这似乎是微软的错误设置属性显示=Dynmaic的时候,是有一个简单的解决方法不改变预期的行为

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.

推荐答案

您的页面不提交,因为该按钮时要点击将鼠标移动到下了。这是因为它获得焦点和验证-的ErrorMessage消失到左边。
如果插入&LT; BR /方式&gt; 在它工作的按钮前

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.

通常情况下,我使用*作为文本和使用来显示的ErrorMessage(S):

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" />

或者,如果使用ASP.Net Ajax的,你可以用漂亮的控制像的。

这篇关于ASP.NET验证设置问题时显示= QUOT;动态&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:29