0

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?

1
  • why have you put "this.retire" in onclick? It is just "retire". Commented Jan 18, 2013 at 16:05

1 Answer 1

4

Change

OnClick="this.retire"

to

OnClick="retire"

Server Event Handling in Web Forms Pages

Sign up to request clarification or add additional context in comments.

3 Comments

Oh programming, it's just funny sometimes :)
@SonerGönül: Funny naming of the method, so it does exactly what it is supposed to do ;-)
What happened to question you asked a few minutes ago? I think your problem in that question is ElementAt method is zero based so it is ok to gives as a result B, IMO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.