我想在我的代码末尾插入操作完成时显示一个警告框。有没有简单的方法来显示某种警告框,显示“插入成功”并显示OK按钮。点击“确定”然后应该重定向到特定页面。在警告对话框中点击按钮时重定向
我正在使用的代码:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
"alertMessage", "alert('Inserted Successfully')", true);
我想在我的代码末尾插入操作完成时显示一个警告框。有没有简单的方法来显示某种警告框,显示“插入成功”并显示OK按钮。点击“确定”然后应该重定向到特定页面。在警告对话框中点击按钮时重定向
我正在使用的代码:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
"alertMessage", "alert('Inserted Successfully')", true);
ClientScript.RegisterStartupScript(typeof(Page), "alertMessage",
"<script type='text/javascript'>alert('Inserted Successfully');window.location.replace('http://stackoverflow.com');</script>");
简单,只是单纯的警报()调用后立即重定向:
alert('Your Text over here');
window.location.href="your url comes here";
不然,如果你想使用确认框
if(confirm("Your Text over here"))
{
window.location.href = "your url comes here";
}
您可以采取的办法中的任何一个:
第一种方法: 可以使用警告对话框,并通知用户。一旦用户点击确定按钮,它将重定向到该网站。但如果用户关闭对话框,它也会重定向。
原因:alert()方法从不返回任何确认。
System.Text.StringBuilder javaScript = new System.Text.StringBuilder();
string scriptKey = "ConfirmationScript";
javaScript.Append("var userConfirmation = window.confirm('" + "Inserted Successfully" + "');\n");
javaScript.Append("window.location='http://www.YourSite.com/';");
ClientScript.RegisterStartupScript(this.GetType(), scriptKey, javaScript.ToString(), true);
方法二: 可以使用确认()方法,它会显示OK &取消对用户按钮&点击它会告诉按钮点击得到了其中。
System.Text.StringBuilder javaScript = new System.Text.StringBuilder();
string scriptKey = "ConfirmationScript";
javaScript.Append("var userConfirmation = window.alert('" + "Inserted Successfully" + "');\n");
javaScript.Append("if (userConfirmation == true)\n");
javaScript.Append("window.location='http://www.YourSite.com/';");
ClientScript.RegisterStartupScript(this.GetType(), scriptKey, javaScript.ToString(), true);
但我想重定向我的网页。像“abc.aspx” – 2013-05-04 10:22:17
好吧无论你想要什么网址什么问题呢? – Dolo 2013-05-04 10:23:08
当我把完整的URL放在window.location.replace(“”)。我的会话很清晰,它直接显示我的登录页面。 会话问题? – 2013-05-04 10:25:01