Nie*_*man 7 javascript c# asp.net redirect alert
之后,当我重定向到另一个页面时,如何使我的代码在代码中工作?我有一个asp按钮控件,当我点击该按钮时我想要提醒,然后导航到另一个页面.当我Response.Redirect在我的代码中(在JS代码之前或之后)时,8次尝试都没有.当我评论重定向时,一些(2,7和8)工作.
//Try one
ScriptManager.RegisterStartupScript(this, GetType(), "test", "alert('test1');", true);
//Try two
ClientScript.RegisterClientScriptBlock(typeof(Page), "test", "test2");
//Try three
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "alertMessage()", true);
//Try four
ClientScript.RegisterStartupScript(GetType(), "CallMyFunction", "alertMessage()", true);
//Try five
ClientScript.RegisterStartupScript(GetType(), "CallMyFunction", "javascript: alertMessage(); ", true);
//Try six
ClientScript.RegisterClientScriptBlock(GetType(), "CallMyFunction", "<script>alert('test4')</script>");
//Try seven
Response.Write("<script>alert('test5');</script>");
//Try eight
string script = "alert('test6')";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CallMyString", script, true);
response.redirect("pageUrlHere");
//With this code above, none of the js functions (alerts) work
//response.redirect("pageUrlHere");
//With this commented out, try 2, 7 and 8 work.
Run Code Online (Sandbox Code Playgroud)
JS功能:
function alertMessage() {
alert('test3');
}
Run Code Online (Sandbox Code Playgroud)
chr*_*dam 10
您可以尝试以下方法:
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect",
"alert('test 9'); window.location='" +
Request.ApplicationPath + "/anotherpage.aspx';",true);
Run Code Online (Sandbox Code Playgroud)