Button OnClick event not working.

Hi folks,

I am having trouble with two buttons on a page. I dragged them on to the page and then double- clicked each of them in order to create the OnClick events.

I added my code to the events, but when I click the buttons, their respective events aren’t being called.

I am very confused!

Any help is appreciated, thanks!

My .aspx code:


My Code behind:

protected void Button3_Click(object sender, EventArgs e)
        int id = int.Parse(queryString);

        #region LiveDatabase
        //string connection = ConfigurationManager.ConnectionStrings["LiveDatabase"].ToString();

        #region MySqlDatabase
        string connection = ConfigurationManager.ConnectionStrings["MySqlDatabase"].ToString();

        MySql.Data.MySqlClient.MySqlConnection MyConn = new MySql.Data.MySqlClient.MySqlConnection(connection);

        string query = "UPDATE property "
                       + "SET display = 'Y' "
                       + "WHERE id = ?id";

        MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand();
        command.CommandText = query;
        command.Connection = MyConn;
        command.Parameters.AddWithValue("?id", id);

            Label7.Visible = true;
            Label7.Text = "The property will now be visible to customers.";
        catch (Exception)
            Label7.Visible = true;
            Label7.Text = "There was an error with your request. Please try again later.";
    protected void Button4_Click(object sender, EventArgs e)
        Label7.Visible = true;
        Label7.Text = "I don't know why this works and the other button doesn't.";

Hi,I have a question regarding your Q. Have u put any validation control in your page?If yes, then answer is validation control prevents your page  to postback. if you want to check remove CausesValidation=”true” and check again. It will work.

Hi,I’ve tried removing the CausesValidation=”true” and it still doesn’t work.I’m very confused!

donpisci:I’ve tried removing the CausesValidation=”true” and it still doesn’t work.I’m very confused!It may happen sometimes..just remove that button  place the new button then try it will work../