代码之家  ›  专栏  ›  技术社区  ›  Ievgen

带有自定义控件的asp.net RequiredFieldValidator

  •  2
  • Ievgen  · 技术社区  · 15 年前

    我需要通过RequiredFieldValidator在客户端验证我的自定义控件。

    我向自定义控件类添加了属性:

    [ValidationProperty("Text")]
        public class WatermarkTextBox : System.Web.UI.UserControl
    {
    }
    

    它看起来像工作,但它总是使提交到服务器。我怎么能只在客户端检查呢?

    1 回复  |  直到 15 年前
        1
  •  4
  •   TheGeekYouNeed    15 年前

    你需要像这样使用CustomValidator

    <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ValidateCheckBox"
    ErrorMessage="Please enter something.">
    

    ClientValidationFunction是javascript函数的名称