的RequiredFieldValidator的IsValid返回上可见=假的假的控制 [英] RequiredFieldValidator IsValid returning false on visible = false control

查看:122
本文介绍了的RequiredFieldValidator的IsValid返回上可见=假的假的控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当文本框为的visible = false 时,应该的RequiredFieldValidator不能运行。

I want that when the textbox is visible = false, the RequiredFieldValidator shouldn't run.

这是我的aspx code:

This is my aspx code:

<asp:TextBox runat="server" ID="txtAmt" MaxLength="7" Style="width: 100px;"/>
                    <asp:RequiredFieldValidator ValidationGroup="ln" runat="server" ControlToValidate="txtAmt"
                        Display="Dynamic" ErrorMessage="Required" />

在后面

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           txtAmt.Visible = false;
        }
    }

,但在我的按钮单击处理程序,当我做了 Page.IsValid ,它返回如果文本框是空的。任何想法如何解决这个问题呢?

and yet in my button click handler, when I do a Page.IsValid, it returns false if textbox is empty. Any idea how to solve this issue?

推荐答案

只是分配一个ID给验证并禁用它。

Just assign an ID to the validator and disable it.

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           txtAmt.Visible = false;

         if(!txtAmt.visible) { txtamtValidator.Enabled=false};

        }
    }

这篇关于的RequiredFieldValidator的IsValid返回上可见=假的假的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆