2010-11-16 84 views
0

我有一個單選按鈕列表和文本框都與驗證。customvalidator onServerValidate not firing

<asp:RadioButtonList ID="member" runat="server" RepeatDirection="Horizontal"> 
    <asp:ListItem>Yes</asp:ListItem> 
    <asp:ListItem>No</asp:ListItem> 
</asp:RadioButtonList> 

<asp:requiredfieldvalidator id="unionvalidator" runat="server" controltovalidate="member" errormessage="Required" /> 

Required if member == "yes" 

<asp:TextBox runat="server" ID="union"></asp:TextBox> 
<asp:customvalidator ID="Customvalidator1" runat="server" ValidateEmptyText="true" onServerValidate="UnionValidate" errormessage="Your current union is required" /> 

我的ServerValidate根本沒有啓動。

public void UnionValidate(object source, ServerValidateEventArgs args) 
{ 
    if (member.Text == "yes" && union.Text.Trim() == "") 
     args.IsValid = false; 
} 

回答

1

你是否在你的代碼後面調用了Page.Validate()方法,或者提交按鈕的CausesValidation是否設置爲true?