我的本意是判断textbox中输入的字符串是否符合时间日期yyyy-MM-dd HH:mm格式
可是当我输入错误的格式时Command1_Click中的代码仍然会执行!这意味这程序先执行了Command1_Click中的代码才去判断textbox中的格式不正确!
那位大哥大姐能告诉我这是怎么回事,见鬼了@!@@!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %><html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form id="Form1" runat="server">
        <mobile:TextBox ID="TextBox1" Runat="server">
        </mobile:TextBox>
        <mobile:RegularExpressionValidator ID="RegularExpressionValidator1" Runat="server"
            ControlToValidate="TextBox1" ErrorMessage="格式错误!" ValidationExpression="^(\d{4})(-)(\d{2})(-)(\d{2})(\s+)(\d{2})(:)(\d{2})$">
        </mobile:RegularExpressionValidator>
        <mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click">Command</mobile:Command>    </mobile:Form>
</body>
</html>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.MobileControls.MobilePage
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Command1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>alert('abc!')</script>");
    }
}

解决方案 »

  1.   

    你的验证组呢?<mobile:RegularExpressionValidator ID="RegularExpressionValidator1" Runat="server"
                ControlToValidate="TextBox1" ErrorMessage="格式错误!" ValidationExpression="^(\d{4})(-)(\d{2})(-)(\d{2})(\s+)(\d{2})(:)(\d{2})$" ValidationGroup="T"><mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click" ValidationGroup="T" >Command</mobile:Command>
      

  2.   

    我使用的是移动web控件,command的属性面板里边没有ValidationGroup属性