Joel Werner
Joel Werner

Reputation: 103

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?

Upvotes: 0

Views: 175

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460208

Change

OnClick="this.retire"

to

OnClick="retire"

Server Event Handling in Web Forms Pages

Upvotes: 4

Related Questions