ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "dele", "alert('删帖成功');window.close()", true); 原来好好的,现在又不能执行了,不弹出确认框,也不关闭。怒了,看了几个小时了还是这样。长夜漫漫,搞不出来睡不着啊。我能想到的就是我的页面不止一个UpdatePanel ,后面还有UpdatePanel2,而且 像 ScriptManager.RegisterStartupScript(UpdatePanel2, this.GetType(), "dele", "alert('删除成功');", true);
ScriptManager.RegisterStartupScript(UpdatePanel2, this.GetType(), "dele", "alert('你无权限');", true);
等等都能正确执行。
这是我写的函数:
//删除帖子函数
protected void lbdete_Click(object sender, EventArgs e)
{
//用户是否登录
if (Session["UserID"] != null)
{
//判断是否是管理员或者是对此贴所在的大小版块的斑竹
if (Session["role"].ToString().Equals("管理员") || Class.IssmallBM(Session["UserID"].ToString(), this.laClassID.Text) || Class.IsBigBM(Session["UserID"].ToString(), this.laClassID.Text))
{
if (Card.Dele(this.laCardID.Text) && DB.decrePoint(Session["UserID"].ToString()) && Card.DeleReplys(ViewState["cardid"].ToString()))
{
ScriptManager.RegisterStartupScript(udp, this.GetType(), "dele", "alert('删帖成功');window.close()", true);
}
}
//若是普通用户,则无权限
else
{
this.lbdete.Text = "你无权限";
this.lbdete.Enabled = false;
}
}
//若没有登录,则不能操作
else
{
this.lbdete.Text = "请先登录";
this.lbdete.Enabled = false;
}
}
函数是正确执行了,因为后来的帖子确实删除了。就是那句脚本不执行。
------解决方案--------------------------------------------------------
你试试看把第一个参数换成this.Page
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), _Key, _jsString, true);
------解决方案--------------------------------------------------------
ScriptManager.RegisterStartupScript(udp, this.GetType(), "dele", "alert('删帖成功');window.close()", true);
这里面的"dele"多次重复出现,虽然不一定是出现问题的原因,但最好改成不同的名称。
------解决方案--------------------------------------------------------
ScriptManager.RegisterStartupScript(udp, this.GetType(), "dele", "alert('删帖成功');window.close();", true);
";" 也是个关键..我也有这样过 ..
------解决方案--------------------------------------------------------
"delet" 有点问题
UpdatePanel 不刷新的话 也不能弹出对话框