我想,以驗證列表框列表框是否爲空的或不是我做以下列表框中驗證
protected void isToListEmpty_ServerValidate(object source, ServerValidateEventArgs args)
{
if (toListBox.Items.Count == 0)
{
args.IsValid = false;
}
else args.IsValid = true;
}
<td>
<asp:UpdatePanel ID="second" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListBox id="toListBox" runat="server" Width="150px" Height="200" SelectionMode="Multiple">
</asp:ListBox>
<asp:CustomValidator id="isToListEmpty" runat="server" OnServerValidate="isToListEmpty_ServerValidate" ErrorMessage="Select Student Details" ValidationGroup="verify" ControlToValidate="toListBox"></asp:CustomValidator>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonAdd" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="ButtonRemove" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="ButtonAddAll" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="ButtonRemoveAll" EventName="Click"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
</td>
,但它不爲空的列表框 工作如何檢查呢?請讓我知道
是更新面板驗證器不檢查空的列表框的原因? – NoviceToDotNet 2010-08-22 17:21:30
你能詳細說明它是如何工作的嗎?如果你在'ServerValidate'事件中添加一個斷點,它是否被命中?當斷點被擊中時,Items.Count真的爲零嗎?這段代碼是否也會在空白頁面上失敗(也就是說,其他方法/事件可能會發生干擾?) – Abel 2010-08-22 17:22:33
是不是中斷點? – NoviceToDotNet 2010-08-22 17:23:27