Search code examples
c#code-behindimagebutton

C# Onclick command not functioning


Below is an asp button that I need to run a C# command on the code behind page.

<asp:ImageButton ID="Retire" OnClick="this.retire" ImageUrl="/assets/images/ast/delete_32x32.png" AlternateText="~retire" ToolTip="Retire" runat="server" />

My C# code behind

public void retire(object sender, EventArgs e)
    {
        using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["app_migrationConnectionString"].ConnectionString))
        {
            connection.Open();
            using (SqlCommand cmd = new SqlCommand("UPDATE Apps SET Migration_Phase = '-1' WHERE ID = @ID", connection))
            {
                cmd.Parameters.AddWithValue("@ID", float.Parse(Request.QueryString["ID"]));
            }
            connection.Close();
            Page.Response.Redirect(Page.Request.Url.ToString(), false);
        }
    }

Do I need a different OnClick or am I missing something?


Solution

  • Change

    OnClick="this.retire"
    

    to

    OnClick="retire"
    

    Server Event Handling in Web Forms Pages