我在一個頁面上有一個RequiredFieldValidator問題,其中兩個面板表示兩個不同的視圖,即一次只能看到一個面板,但它們共享同一個提交按鈕。ASP.NET驗證器不會觸發
默認情況下,「BatchReturnPanel」是可見的,「SingleReturnPanel」是隱藏的,在這種情況下頁面上工作的所有驗證就好了。但是,如果我隱藏「批處理」面板並顯示「單..」面板(ChangeViewButton單擊事件),那麼requieredFieldValidator「DropDownListFieldValidator」不會啓動,並且頁面始終被視爲驗證。爲什麼會發生這種情況,如何解決這個問題?感謝您的幫助/
下面是從ASPX頁面提取:
<div>
<asp:DropDownList ID="MDDropDownList" runat="server"></asp:DropDownList>
<asp:RequiredFieldValidator id="DropDownListFieldValidator" runat="server" ControlToValidate="MDDropDownList"
InitialValue="-" ErrorMessage="Please select Master Distributor" EnableClientScript="true" CssClass="error"
Display="Static" ValidationGroup="Voucher" />
<asp:Panel runat="server" ID="BatchReturnPanel">
<p>
<asp:TextBox ID="FirstVoucherTextBox" runat="server" CssClass="Scanner RRS"></asp:TextBox>
<asp:RequiredFieldValidator ID="FirstVoucherFieldValidator" runat="server" ControlToValidate="FirstVoucherTextBox" ValidationGroup="Voucher"
ErrorMessage="Valid Voucher ID for the first voucher in batch is required<br>" Display="Dynamic" CssClass="error" EnableClientScript="false"></asp:RequiredFieldValidator>
</p>
</asp:Panel>
<asp:Panel runat="server" ID="SingleReturnPanel" Visible="false">
<p>
<asp:TextBox ID="SingleVoucherTextBox1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="SingleVoucherTextBox2" runat="server"></asp:TextBox><br />
<asp:TextBox ID="SingleVoucherTextBox3" runat="server"></asp:TextBox><br />
</p>
</asp:Panel>
<asp:Button ID="VoucherSubmitButton" runat="server" Text="Enter"
OnClick="VoucherSubmitButton_Click" UseSubmitBehavior="false" ValidationGroup="Voucher"/>
</div>
<asp:Panel CssClass="grid_4 box" runat="server" ID="ChangeViewPanel">
<asp:LinkButton runat="server" ID="ChangeViewButton"
onclick="ChangeViewButton_Click">Single item return mode</asp:LinkButton>
</asp:Panel>
爲什麼你有這個?'UseSubmitBehavior = 「假」' – Bastardo
嘗試設置'FirstVoucherFieldValidator'的'ValidationGroup'東西比'Voucher'不同,當你點擊'ChangeViewButton'如果'BatchReturnPanel'可見,則將其設置爲'Voucher'。 – Bastardo
您在哪種方法中填充'MDDropDownList'?你也可以展示這個嗎? –