我在表单 id="form1" runat="server" 标记之后在我的 aspx 页面中有这个:(必须去掉 > 和 <)
<script type="text/javascript">
function openLocationForm(locationId)
{
window.open('FlagLocationViewForm.aspx?id=' + locationId), '_blank');
}
</script>
FlagLocationViewForm.aspx 页面确实存在并且需要传递给它的参数。如果我只是让页面加载 Response.Redirect("FlagLocationViewForm.aspx"); 它加载,但不在新标签中。
我在 .cs 文件中有这个,该文件与具有上述脚本的这个 .aspx 页面相关联。
protected void GridViewCustomerList_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridViewSelectEventArgs args = (GridViewSelectEventArgs)e;
GridViewRow row = GridViewCustomerList.Rows[args.NewSelectedIndex];
int customerId = Convert.ToInt32(row.Cells[6].Text);
string scriptToRun = "openLocationForm('" + customerId.ToString() + "');";
Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), scriptToRun, true);
}
该页面导致 GridViewCustomerList_SelectedIndexChanging 触发 - 一切正常。但是 RegisterStartupScript 没有做任何事情。如果我将以下内容替换为 Page.ClientScript.RegisterStartupScript 行:
Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('Hello');", true);
我收到显示“你好”的警报。
谁能告诉我我做错了什么?