关于在asp.net中嵌入confirm()函数的问题~
我写的程序如下~
public void del_record(Object sender,DataListCommandEventArgs e)
{
//Response.Write( " <script language=javascript> confirm( '是否执行此次操作? '); </ "+ "script> ");
Response.Write( " <script language=javascript> if(confirm( '是否执行此次操作? ')==true) </ "+ "script> ");
Response.Write( " <script language=javascript> { </ "+ "script> ");
string sqlstring= "delete from news where ID= "+((Label)e.Item.FindControl( "IDkj ")).Text;
SqlCommand comm=new SqlCommand(sqlstring,conn);
comm.ExecuteNonQuery();
Response.Write( " <script language=javascript> alert( '删除记录成功 '); </ "+ "script> ");
Response.Write( " <script language=javascript> } </ "+ "script> ");
Response.Write( " <script language=javascript> else if(confirm( '是否执行此次操作? ')==false) </ "+ "script> ");
Response.Write( " <script language=javascript> { </ "+ "script> ");
Response.Write( " <script language=javascript> alert( '删除记录失败 '); </ "+ "script> ");
Response.Write( " <script language=javascript> } </ "+ "script> ");
}
问题是我不管是点是还是否还是点是,都会出现提示 "删除记录成功 "和 "删除记录失败 "的提示窗,请帮忙解决下~分不多了~只有20分~大家别嫌少啊~
------解决方案--------------------你这样写肯定是不行的。改成这样试试:
del_record.Attribute.Add( "onclick ", "return confirm( '是否执行此次操作? ') ");
public void del_record(Object sender,DataListCommandEventArgs e)
{
string sqlstring= "delete from news where ID= "+((Label)e.Item.FindControl( "IDkj ")).Text;
SqlCommand comm=new SqlCommand(sqlstring,conn);
comm.ExecuteNonQuery();
Response.Write( " <script language=javascript> alert( '删除记录成功 '); </ "+ "script> ");
Response.Write( " <script language=javascript> } </ "+ "script> ");
Response.Write( " <script language=javascript> else if(confirm( '是否执行此次操作? ')==false) </ "+ "script> ");
Response.Write( " <script language=javascript> { </ "+ "script> ");
Response.Write( " <script language=javascript> alert( '删除记录失败 '); </ "+ "script> ");
Response.Write( " <script language=javascript> } </ "+ "script> ");
}