ASP.NET不执行Button的onClick事件,查了一天也没解决,求大家帮忙!


抱歉,代码有点多,是一个注册功能的页面,.aspx的倒数第五行是那个不起作用的btn。
.cs最下面是绑定的事件

.aspx文件的代码


 <form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
    <ContentTemplate>
        <div id="RegisterBox" runat="server">
            <asp:Label runat="server" SkinId="InfoTitle">邮箱</asp:Label><br />
            <asp:TextBox runat="server" AutoPostBack="true" ID="User_EMail" OnTextChanged="User_EMail_TextChanged" 
                CssClass="RegisterText"></asp:TextBox><br />
            <asp:RegularExpressionValidator runat="server" ControlToValidate="User_EMail" CssClass="Validator" ID="EmailValidator"
                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            <asp:Label runat="server" ID="TipEmail" CssClass="Validator"></asp:Label><br />
            <asp:Label runat="server" SkinId="InfoTitle">昵称</asp:Label><br />
            <asp:TextBox runat="server" AutoPostBack="true" ID="User_NickName" OnTextChanged="User_NickName_TextChanged" 
                CssClass="RegisterText"></asp:TextBox><br />
            <asp:RegularExpressionValidator runat="server" ID="NickNameValidator" ControlToValidate="User_NickName" CssClass="Validator" 
                ValidationExpression="([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9]){2,14}"></asp:RegularExpressionValidator>
            <asp:Label runat="server" ID="TipNickName" CssClass="Validator"></asp:Label><br />
            <asp:Label runat="server" SkinId="InfoTitle">密码</asp:Label><br />
            <asp:TextBox runat="server" ID="User_Pwd" TextMode="Password" CssClass="RegisterText"></asp:TextBox><br />
            <asp:RegularExpressionValidator runat="server" ControlToValidate="User_Pwd" 
                ErrorMessage="密码只能为6-20个非空格字符!" CssClass="Validator" ID="PwdValidator"
                ValidationExpression="[\S]{6,20}"></asp:RegularExpressionValidator><br />
            <asp:Label runat="server" SkinId="InfoTitle">确认密码</asp:Label><br />
            <asp:TextBox runat="server" ID="User_RePwd" TextMode="Password" CssClass="RegisterText"></asp:TextBox><br />
            <asp:CompareValidator runat="server" ControlToCompare="User_Pwd" CssClass="Validator" ID="RePwdValidator"
                ControlToValidate="User_RePwd" ErrorMessage="重复密码必须和密码相同!"></asp:CompareValidator><br />
            <asp:Label runat="server" SkinId="InfoTitle">性别</asp:Label><br />
            <asp:RadioButtonList runat="server" ID="User_Gender" CssClass="Gender" RepeatDirection="Horizontal" RepeatLayout="Flow">
                <asp:ListItem Text="男" Value="1"></asp:ListItem>
                <asp:ListItem Text="女" Value="0"></asp:ListItem>
            </asp:RadioButtonList><br />
            <asp:RequiredFieldValidator runat="server" CssClass="Validator" ErrorMessage="请选择性别!" 
                ControlToValidate="User_Gender"></asp:RequiredFieldValidator><br />
            <asp:Label runat="server" SkinId="InfoTitle">居住地</asp:Label><br />
            <asp:DropDownList runat="server" ID="User_Province" AutoPostBack="true"
                onselectedindexchanged="User_Province_SelectedIndexChanged">
                <asp:ListItem Text="省份" Value="0"></asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList runat="server" ID="User_City" style="visibility:hidden;" AutoPostBack="true"
                onselectedindexchanged="User_City_SelectedIndexChanged">
                <asp:ListItem Text="市/地区" Value="0"></asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList runat="server" ID="User_District" style="visibility:hidden;">
                <asp:ListItem Text="县/市" Value="0"></asp:ListItem>
            </asp:DropDownList><br />
            <asp:Label runat="server" ID="TipArea" CssClass="Validator" Text="请选择居住地!"></asp:Label><br />
            <asp:Label runat="server" SkinId="InfoTitle">生日</asp:Label><br />
            <asp:DropDownList runat="server" ID="User_BirthYear" AutoPostBack="true" CssClass="DropList"
                onselectedindexchanged="User_BirthMonthAndBirthYear_SelectedIndexChanged">
                <asp:ListItem Text="年份" Value="0"></asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList runat="server" ID="User_BirthMonth" AutoPostBack="true"
                onselectedindexchanged="User_BirthMonthAndBirthYear_SelectedIndexChanged">
                <asp:ListItem Text="月份" Value="0"></asp:ListItem>
                <asp:ListItem Text="1" Value="1"></asp:ListItem>
                <asp:ListItem Text="2" Value="2"></asp:ListItem>
                <asp:ListItem Text="3" Value="3"></asp:ListItem>
                <asp:ListItem Text="4" Value="4"></asp:ListItem>
                <asp:ListItem Text="5" Value="5"></asp:ListItem>
                <asp:ListItem Text="6" Value="6"></asp:ListItem>
                <asp:ListItem Text="7" Value="7"></asp:ListItem>
                <asp:ListItem Text="8" Value="8"></asp:ListItem>
                <asp:ListItem Text="9" Value="9"></asp:ListItem>
                <asp:ListItem Text="10" Value="10"></asp:ListItem>
                <asp:ListItem Text="11" Value="11"></asp:ListItem>
                <asp:ListItem Text="12" Value="12"></asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList runat="server" ID="User_BirthDay">
                <asp:ListItem Text="日期" Value="0"></asp:ListItem>
            </asp:DropDownList><br />
            <asp:Label runat="server" ID="TipBirthDay" class="Validator" Text="请选择出生日期!"></asp:Label><br />
            <asp:Label runat="server" SkinId="InfoTitle">验证码</asp:Label><br />
            <asp:TextBox runat="server" ID="CAPTCHA" Columns="4" CssClass="RegisterText CAPTCHA" Width="119px"></asp:TextBox>
            <asp:Image runat="server" ID="CAPTCHAimg" CssClass="CAPTCHAimg" AlternateText="nonPic" /><br />
            <asp:Label runat="server" ID="TipCAPTCHA" class="Validator" Text="验证码输入错误!"></asp:Label>
            <asp:Button runat="server" ID="ConfirmRegister" OnClick="ConfirmRegister_Click" CssClass="ConfirmRegister" />
        </div>
</ContentTemplate>
</asp:UpdatePanel>
</form>

.cs文件的代码


 public partial class UserRegister : System.Web.UI.Page
{
    /// <summary>
    /// 初始化居住地和出生日期
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (int i = DateTime.Now.Year; i >= 1900; i--)
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                User_BirthYear.Items.Add(li);
            }
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EncloudConnectionString"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from [S_Province]", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                ListItem li = new ListItem(dr[1].ToString(), dr[0].ToString());
                User_Province.Items.Add(li);
            }
        }
    }

    /// <summary>
    /// 检测邮箱格式和是否重复
    /// </summary>
    protected void User_EMail_TextChanged(object sender, EventArgs e)
    {
        EmailValidator.Validate();
        if (EmailValidator.IsValid)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EncloudConnectionString"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select [User_Email] from [ZOLUser] where [User_Email]='" + User_EMail.Text + "'", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                TipEmail.Text = "邮箱不能重复使用!";
            }
            else
            {
                TipEmail.Text = "";
            }
        }
        else
        {
            TipEmail.Text = "邮箱格式不正确!";
        }
    }

    /// <summary>
    /// 检测昵称格式和是否重复
    /// </summary>
    protected void User_NickName_TextChanged(object sender, EventArgs e)
    {
        NickNameValidator.Validate();
        if (NickNameValidator.IsValid)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EncloudConnectionString"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select [User_NickName] from [ZOLUser] where [User_NickName]='" + User_NickName.Text + "'", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                TipNickName.Text = "昵称已被使用!";
            }
            else
            {
                TipNickName.Text = "";
            }
        }
        else
        {
            TipNickName.Text = "昵称只能是2-14个汉字、字母或数字!";
        }
    }

    /// <summary>
    /// MD5加密方法
    /// </summary>
    /// <param name="sDataIn">需要加密的字符串</param>
    /// <param name="move">偏移量</param>
    /// <returns>加密后的字符串</returns>
    public string GetMD5(string sDataIn, string move)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] bytValue, bytHash;
        bytValue = System.Text.Encoding.UTF8.GetBytes(move + sDataIn);
        bytHash = md5.ComputeHash(bytValue);
        md5.Clear();
        string sTemp = "";
        for (int i = 0; i < bytHash.Length; i++)
        {
            sTemp += bytHash[i].ToString("x").PadLeft(2, '0');
        }
        return sTemp;
    }

    /// <summary>
    /// 通过出生年和月动态加载出生日
    /// </summary>
    protected void User_BirthMonthAndBirthYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!(User_BirthYear.SelectedIndex == 0) && !(User_BirthMonth.SelectedIndex == 0))
        {
            while (User_BirthDay.Items.Count > 1)
            {
                User_BirthDay.Items.RemoveAt(1);
            }
            int BirthYear = Convert.ToInt32(User_BirthYear.SelectedValue);
            int BirthMonth = Convert.ToInt32(User_BirthMonth.SelectedValue);
            for (int i = 1; i <= DateTime.DaysInMonth(BirthYear, BirthMonth); i++)
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                User_BirthDay.Items.Add(li);
            }
        }
    }

    /// <summary>
    /// 通过省动态加载市和县
    /// </summary>
    protected void User_Province_SelectedIndexChanged(object sender, EventArgs e)
    {
        while (User_City.Items.Count > 1)
        {
            User_City.Items.RemoveAt(1);
        }
        while (User_District.Items.Count > 1)
        {
            User_District.Items.RemoveAt(1);
        }
        if (!(User_Province.SelectedIndex == 0))
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EncloudConnectionString"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from [S_City] where [ProvinceID]='" + User_Province.SelectedValue + "'", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                ListItem li = new ListItem(dr[1].ToString(), dr[0].ToString());
                User_City.Items.Add(li);
            }
            User_City.Style.Add("visibility", "inherit");
        }
        else
        {
            User_City.Style.Add("visibility", "hidden");
        }
    }

    /// <summary>
    /// 通过市动态加载县
    /// </summary>
    protected void User_City_SelectedIndexChanged(object sender, EventArgs e)
    {
        while (User_District.Items.Count > 1)
        {
            User_District.Items.RemoveAt(1);
        }
        if (!(User_City.SelectedIndex == 0))
        {

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EncloudConnectionString"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from [S_District] where [CityID]='" + User_City.SelectedValue + "'", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                ListItem li = new ListItem(dr[1].ToString(), dr[0].ToString());
                User_District.Items.Add(li);
            }
            User_District.Style.Add("visibility", "inherit");
        }
        else
        {
            User_District.Style.Add("visibility", "hidden");
        }
    }
    protected void ConfirmRegister_Click(object sender, EventArgs e)
    {
        Response.Write("编程之神,请赐予我力量!!成功吧!!!!!");
    }
}

试了各种各样的方法,就是不能让这个事件起作用,真心求助!

.net c# asp.net

game456 11 years, 11 months ago

可以google之,例如下面这个链接 AJAX下不能使用RESPONSE.WRITE 脚本的解决方案

事件处理函数应该是被调用了,只是没有输出。

Flaya answered 11 years, 11 months ago

Your Answer