下面是一个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或者我错过了什么?
答案 0 :(得分:4)