JS截断后台存储过程
前台的asp:GridView模版组里加入了这样一个button
<asp:Button ID= "button1 " runat= "server " Text= "删除 " OnClick= "button1_Click " onClientClick= "return confirm( '确实要删除吗? ') "/>
调试正常,但当点击确定后,后台操作完全被忽略,存储过程没有被执行,而是直接跳到response.write一行,下面是代码:
try
{
connection.Open();
cmd.ExecuteNonQuery();
Response.Write( " <script language= 'javascript '> alert( '操作成功! ');window.location.href= 'UserManager.aspx '; </script> ");
}
====
改用后台强制后效果一样(为方便找到按钮控件,已将ID改为btn_del)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnDelete = (Button)e.Row.FindControl( "btn_del ");
btnDelete.Attributes.Add( "OnClick ", "return confirm( '确实要删除吗? ') ");
}
}
请教达人!!!!
------解决方案--------------------http://topic.csdn.net/t/20060629/15/4850815.html
------解决方案--------------------还有就是GridView模板里button貌似不能这样委托事件吧、
得用
<asp:Button ID= "button1 " runat= "server " Text= "删除 " OnCommand= "button1_Click "
CommandArguments= " ">