重新开贴 RegisterStartupScript中的alert 弹出框无效
前台代码
<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(function () {
$("#delete").live("click",function () {
var $id = $(this).attr("deleteid");
$("#form1").attr("action", "ReaderBorrowHistory.aspx?cid=" + $id);
$("#form1").submit();
});
});
</script>
<body>
<form id="form1" method="post" action="ReaderBorrowHistory.aspx">
<div>
<table id="Table1" style="font-family:Tahoma; font-size:12px; border-collapse:collapse ;" align="center" bgcolor="#f1f0f4" border="0" width="398">
<tr>
<td align ="center" >
<h1><font face ="GB_2312">借阅记录</font></h1>
<hr width ="90%" />
</td>
</tr>
<tr>
<td align ="center">
<%=outputTable %> <!-- outputtable是在后台定义的公共变量 用于放置动态拼接出的一个table -->
</td>
</tr>
</table>
</div>
</form>
</body>
后台代码
public string outputTable;
protected void Page_Load(object sender, EventArgs e)
{
//if (!this.IsPostBack)
//{
// GridViewDataBind();
//}
StringBuilder sText = new StringBuilder();
sText.Append("<table id='table2'><tr><td>");
sText.Append("选择</td><td>");
sText.Append("题名/作者</td><td>出版信息</td>");
sText.Append("<td>借阅时间</td><td>应还时间</td></tr>");
Borrow borrow = new Borrow();
DataSet ds = borrow.QueryCurrentBorrow(Session["userID"].ToString());
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
sText.Append("<tr><td> <INPUT name=‘chkSon’ id='hkSon1' type='checkbox' value=" + row["BookID"].ToString() + "/></td>");
sText.Append("<td>" + row["BookName"].ToString() + "/ "
+ row["BookAuthor"].ToString() + "</td>");
sText.Append("<td>" + row["BookPublish"].ToString() + ""
+ row["BookPublishDate"].ToString() + "</td>");
sText.Append("<td>" + DateTime.Parse(row["BorrowBeginDate"].ToString()).ToString("yyyy-MM-dd") + "</td><td>"
+ DateTime.Parse(row["BorrowEndDate"].ToString()).ToString("yyyy-MM-dd") + "</td>");
sText.Append("<td><span>编辑</span></td>");
sText.Append("<td><span id='delete' deleteid='" + row["BorrowID"].ToString() + "'>删除</span></td></tr>");
}
sText.Append("</table>");
outputTable = sText.ToString();
}
else
{
outputTable = "<h1>该用户目前没有借书</h1>";
}
if (Request["cid"] != null)
{
int cid = int.Parse(Request["cid"]);
bool result = borrow.DeleteByProc(cid);
if (result)
{
Page.ClientScript.RegisterStartupScript (this.GetType(),"","<script> alert('删除记录成功');</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script> alert('删除记录失败');</script>");
}
}
}
现在的问题是虽然能够正常的删除记录但是RegisterStartupScript中的alert不起作用,删除成功的话,不会弹出对话框来提示删除成功,我调试了一下,也没报什么错误,这是怎么回事呢?大家帮帮忙,谢谢!
[解决办法]
换成 RegisterClientScriptBlock 看看
或者
Page.ClientScript.RegisterStartupScript (this.GetType(),"这里加一个key看看","<script> alert('删除记录成功');</script>");
[解决办法]
<form id="form1" method="post" action="ReaderBorrowHistory.aspx">
跟这个有没有关系。JQ里面写这里就。。
