C#Onclick命令无法正常工作

时间:2013-01-18 16:01:31

标签: c# code-behind imagebutton

下面是一个asp按钮,我需要在代码隐藏页面上运行C#命令。

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

我的C#代码背后

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);
        }
    }

我是否需要不同的OnClick或者我错过了什么?

1 个答案:

答案 0 :(得分:4)

更改

OnClick="this.retire"

OnClick="retire"

Server Event Handling in Web Forms Pages

相关问题