Ok well I have three LinkButtons that all work that execute when clicked, however what I want to do is instead of the LinkButtons being executed individually for them all to be executed within Button1_click. Therefore how do I do this?

Code can be seen below:

protected void Button1_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("INSERT INTO Users(Username,Password,Email,Forename,Surname,Postcode,Telephone) Values('" + TextBox1.Text + "'" + ",'" + TextBox2.Text + "'" + ",'" + TextBox4.Text +"'" + ",'" + TextBox5.Text + "'" + ",'" + TextBox8.Text + "'"+",'" + TextBox6.Text + "'"+",'" + TextBox7.Text + "')", con);
            cmd.ExecuteNonQuery();



        }



        protected void LinkButton1_Click1(object sender, EventArgs e)
        {
         con.Open();
            cmd = new SqlCommand("select * from Users Where Username ='" +TextBox1.Text+"'",con  );
            dr=cmd.ExecuteReader();
                if(dr.Read())

                {

                    Label1.Text = "Username already exists";

                    this.Label1.ForeColor=Color.Red;
                }

                else

                {
                      Label1.Text = "Username avaliable";

                      this.Label1.ForeColor = Color.Green;

                }
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("select * from Users Where Email ='" + TextBox4.Text + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {

                Label2.Text = "Email already exists";

                this.Label2.ForeColor = Color.Red;
            }

            else
            {
                Label2.Text = "Email avaliable";

                this.Label2.ForeColor = Color.Green;

            }
        }

        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("select * from Users Where Surname ='" + TextBox8.Text + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {

                Label3.Text = "Surname already exists";

                this.Label3.ForeColor = Color.Red;
            }

            else
            {
                Label3.Text = "Surname avaliable";

                this.Label3.ForeColor = Color.Green;

            }

Just call them like you would do any other method

protected void Button1_Click(object sender, EventArgs e) {
    LinkButton1_Click(sender, e);
    LinkButton2_Click(sender, e);
    LinkButton3_Click(sender, e);
}

Thanks for the help it worked. I have another question, what I want to do is if all my username, email, and surname are avaliable it exeutes the following:

cmd = new SqlCommand("INSERT INTO Users(Username,Password,Email,Forename,Surname,Postcode,Telephone) Values('" + TextBox1.Text + "'" + ",'" + TextBox2.Text + "'" + ",'" + TextBox4.Text +"'" + ",'" + TextBox5.Text + "'" + ",'" + TextBox8.Text + "'"+",'" + TextBox6.Text + "'"+",'" + TextBox7.Text + "')", con);

How would I do it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.