按钮单击不触发

时间:2014-05-08 13:31:48

标签: asp.net

我想知道为什么我的按钮停止了它的事件..

这是我的标记:

<asp:Button ID="btnSubmit" runat="server" BackColor="#444444" BorderStyle="None"  ForeColor="White" Height="40px" OnClick="btnSubmit_Click" Text="Register" Width="603px"  />

这是我的代码:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    string username = txtUID.Text;
    string password = txtRegPass.Text;
    string password2 = txtRegPassConfirm.Text;
    string clientid = Convert.ToString(Session["UniqueID"]);

    if (Databasescripts.checkforExistingAccount(username) == false)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Username already taken!');", true);
    }

    else if (password != password2)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Password does not match!');", true);
    }
    else
    {
        ///Email validation page to client
        MailMessage MyMailMessage = new MailMessage();
        MyMailMessage.From = new MailAddress("noreplyasiainsph@gmail.com", "Asia Insurance Philippines");
        MyMailMessage.To.Add(txtRegEmail.Text.ToString());
        MyMailMessage.Subject = "asiainsphclaims.com- Verify Email";
        MyMailMessage.IsBodyHtml = true;

        MyMailMessage.Body = "<body bgcolor=\"#F5F5F5\"><center><font face=\"Cambria\" size=2><img src=\"http://i1332.photobucket.com/albums/w609/asiainsphclaims/48880_zps3cdf1a95.jpg\" border=\"0\" alt=\"Asia Insurance (Philippines) Corporation\"/><br>";

        MyMailMessage.Body += "Account Registration Successful!<br><br>";
        MyMailMessage.Body += "Your account details are as follows:<br>";
        MyMailMessage.Body += "<br>Username: <b>" + txtUID.Text.ToString() + "</b><br>";
        MyMailMessage.Body += "<br>Password: <b>" + txtRegPass.Text.ToString() + "</b><br>";
        MyMailMessage.Body += "Click on the link below to verify your E-mail Address<br>";
        MyMailMessage.Body += "<a href=\"http://www.asiainsphclaims.com/VerifyEmail.aspx\">VERIFY NOW</a><br>";
        MyMailMessage.Body += "<br><br><br><a href=\"http://twitter.com/AsiaInsurancePH\" target=\"_blank\"><img src=\"http://i1332.photobucket.com/albums/w609/asiainsphclaims/Twitter_zps36d6a150.png\" border=\"0\" alt=\"Follow us on Twitter!\"></a>";
        MyMailMessage.Body += "<a href=\"https://www.facebook.com/pages/Asia-Insurance-Philippines/660815073932476\" target=\"_blank\"><img src=\"http://i1332.photobucket.com/albums/w609/asiainsphclaims/Facebook_zps562abd5c.png\" border=\"0\" alt=\"Like us on Facebook!\"/></a>";
        MyMailMessage.Body += "<br><br><font size=3><em>Asia Insurance (Philippines) Corporation</em></font>";
        MyMailMessage.Body += "<br>15/F Tytana Bldg. Plaza Lorenzo Ruiz Binondo, Manila, Philippines <br>Telephone: (632)241-5201 | Fax: (632)243-3216 | Email: <a href=\"mailto:aipc@asiains.com.ph\">aipc@asiains.com.ph</a>";

        SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
        SMTPServer.Port = 587;
        SMTPServer.Credentials = new System.Net.NetworkCredential("noreplyasiainsph@gmail.com", "apcAPC2013");
        SMTPServer.EnableSsl = true;

        SMTPServer.Send(MyMailMessage);
        Databasescripts.proceedRegister();
        Response.Redirect("RedirecttAfterAccountCreation.aspx");
    }

}

我的解决方案:

就是我能解决自己的问题。我记得我已经在用户可以更新其电子邮件的地方放置了一个“弹出窗口”,我在那里进行了验证,而这又是在等待用户的输入。我能够通过从电子邮件更新中删除验证来解决此问题。

1 个答案:

答案 0 :(得分:0)

尝试加入CausesValidation = false

<asp:Button ID="btnSubmit" runat="server" CausesValidation="false" BackColor="#444444" BorderStyle="None"  ForeColor="White" Height="40px" OnClick="btnSubmit_Click" Text="Register" Width="603px"  />