none
验证控件 RRS feed

答案

  • CustomValidator的错误在ValidationSummary里面没有体现

    或者:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CSharp.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script>
            function ClientValidate(source, arguments) {
                arguments.IsValid = (arguments.Value != "");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:CustomValidator ClientValidationFunction="ClientValidate" ID="CustomValidator1" runat="server" ErrorMessage="错误,必须写名字!" ValidateEmptyText="True" ControlToValidate="TextBox1"></asp:CustomValidator>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
            </div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </form>
    </body>
    </html>

    我的博客园
    慈善点击,点击此处
    和谐拯救危机,全集下载,净化人心

    2012年11月7日 1:45

全部回复

  • 你代码如何写的?参考:

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="错误,必须写名字!" OnServerValidate="CustomValidator1_ServerValidate" ValidateEmptyText="True" ControlToValidate="TextBox1"></asp:CustomValidator>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />

    后台代码:

    public partial class WebForm1 : System.Web.UI.Page
        {
            protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
            {
                args.IsValid = (args.Value.Trim() != string.Empty);
            }
        }

    或者请参考:

    http://axislover.blog.163.com/blog/static/107765152008111412138144/


    我的博客园
    慈善点击,点击此处
    和谐拯救危机,全集下载,净化人心

    2012年11月7日 1:21
  • CustomValidator的错误在ValidationSummary里面没有体现

    或者:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CSharp.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script>
            function ClientValidate(source, arguments) {
                arguments.IsValid = (arguments.Value != "");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:CustomValidator ClientValidationFunction="ClientValidate" ID="CustomValidator1" runat="server" ErrorMessage="错误,必须写名字!" ValidateEmptyText="True" ControlToValidate="TextBox1"></asp:CustomValidator>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
            </div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </form>
    </body>
    </html>

    我的博客园
    慈善点击,点击此处
    和谐拯救危机,全集下载,净化人心

    2012年11月7日 1:45