Cancel submit button event in ASP and C#
<p>I am trying to cancel a submit event if a response is true. I have a submission button in which i am wanting to check if the textbox is same as a value in the database. If it is then it will not allow the update to go ahead.</p>

<p><strong>My C# code</strong></p>

<pre><code>protected void SubmitBtn_Click(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
        conn.Open();
        string sql = "Select count(*) from Student Where Student_Username=@username";
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.Parameters.AddWithValue("username", usernameTxt.Text);
        int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());

        if (temp == 1)
        {
            Response.Write("User already exists");

        }

        conn.Close();

    }

    //SQL Connection and SQL for inserting a new student
    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
    con.Open();

        try
        {
            var sql = "INSERT INTO Student (Student_Username, Student_FName, Student_SName, Student_Email, Student_Password, Student_Status) " + "VALUES (@StudentName, @StudentFirstname, @StudentSurname, @StudentEmail, @StudentPassword, @StudentStatus);";

            using (var cmd = new SqlCommand(sql, con))
            {
                cmd.Parameters.AddWithValue("@StudentName", usernameTxt.Text);
                cmd.Parameters.AddWithValue("@StudentFirstname", firstnameTxt.Text);
                cmd.Parameters.AddWithValue("@StudentSurname", surnameTxt.Text);
                cmd.Parameters.AddWithValue("@StudentEmail", emailTxt.Text);
                cmd.Parameters.AddWithValue("@StudentPassword", passwordTxt.Text);
                cmd.Parameters.AddWithValue("@StudentStatus", statusTxt.Text);
                cmd.ExecuteNonQuery();
            }

            greenPnl.Visible = true;

            usernameTxt.Text = "";
            firstnameTxt.Text = "";
            surnameTxt.Text = "";
            emailTxt.Text = "";
            passwordTxt.Text = "";
            retypePasswordTxt.Text = "";

        }

        catch (Exception ex)
        {

            Response.Write("Error:" + ex.ToString());

        }


    con.Close();

}
</code></pre>

<p>How can i call the eventArgs to cancel it? I know you cant simply <code>e.cancel = true;</code></p>