0

テキストボックスがvisible = falseの場合、 RequiredFieldValidator を実行しないでください。

これは私のaspxコードです:

<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に戻ります。falseこの問題を解決する方法はありますか?

4

2 に答える 2

3

バリデーターに ID を割り当てて無効にするだけです。

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

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

        }
    }
于 2013-05-07T06:11:00.930 に答える
0

JavaScriptを使用すると、これを実現できます

<script type="text/javascript">
        function txtAmtOff()
        {
            document.getElementById("txtAmt").style.display = 'none';
            ValidatorEnable(document.getElementById("txtAmtValidator"), false);
        }
        function txtAmtOn()
        {
            document.getElementById("txtAmt").style.display = 'inline';
            ValidatorEnable(document.getElementById("txtAmtValidator"), true);
        }
    </script>
于 2013-05-07T06:29:05.353 に答える