简体   繁体   English

图像按钮和更新面板

[英]Image button and update panel

I have a Image button defined as follow, 我有一个图像按钮定义如下,

<div>
    <asp:ImageButton ID="btn1" runat="server" ImageUrl="/_LAYOUTS/1033/IMAGES/row.png" />
</div>
<div>
    <asp:RequiredFieldValidator runat="server" ID="reqName" ControlToValidate="txtUserEmail" validationGroup="Page"
        ErrorMessage="enter a email" />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"
        ControlToValidate="txtUserEmail" ErrorMessage="enter a email">  
    </asp:RegularExpressionValidator>
</div>

Now somewhere I got update panel, 现在我有了更新面板,

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <div> // with controls in it that do some calculations without post back

Problem is when my user control loads up, if I try to calculate and press a button in update panel, it checks if text box is empty or not, if it then gives enter a email error which shouldn't be happening. 问题是,当我的用户控件加载完毕时,如果我尝试计算并按下更新面板中的按钮,它将检查文本框是否为空,如果输入的是错误消息,则该文本框应该不会发生。

Now If I add validationGroup="Page" to validators it does work but it then doesn't check if email text box is empty or not. 现在,如果我将validationGroup="Page"添加到验证器,它确实可以工作,但是它不会检查电子邮件文本框是否为空。

Also if I add EnableClientScript=False then again update panel works but doesn't seems to validate email text box. 另外,如果我添加EnableClientScript=False则再次使用更新面板,但似乎无法验证电子邮件文本框。

If you add ValidationGroup="Page" to your validators, you also need to add it to the relevant button(s) and input control(s) otherwise the validators will be in a group on their own with nothing to validate. 如果将ValidationGroup="Page"添加到验证器,则还需要将其添加到相关按钮和输入控件,否则验证器将单独位于一个组中,而无需进行验证。

<div>
    <asp:ImageButton ID="btn1" runat="server" ImageUrl="/_LAYOUTS/1033/IMAGES/row.png" ValidationGroup="Page" />
</div>
<div>
    <asp:RequiredFieldValidator runat="server" ID="reqName" ControlToValidate="txtUserEmail" ValidationGroup="Page" ErrorMessage="enter a email" />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" ControlToValidate="txtUserEmail" ValidationGroup="Page" ErrorMessage="enter a email" />
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM