这是我的代码
Type cstype = this.GetType();
ClientScriptManager cs = this.ClientScript;
if (!cs.IsStartupScriptRegistered(cstype, "Script"))
{
String csScriptText = "confirm('Are you sure you want to leave the page');document.location='Default.aspx'";
cs.RegisterStartupScript(cstype, "TestScript", csScriptText, true);
}
我正在尝试在我的网络应用程序中实现确认框,当用户点击注销按钮时会出现该确认框...使用选项“确定”并使用上面的代码取消。使用上面的代码我可以在以下情况下重定向到默认页面:用户在确认框中点击“确定”。我想当用户点击确认框中的“取消”按钮时保持在同一页面上。我该怎么做?
最佳答案
确认函数返回一个 bool
值,指示用户是选择“确定”还是取消。因此,您需要做的就是仅在该函数返回 true 时进行重定向:
String csScriptText = "if (confirm('Are you sure you want to leave the page')){document.location='Default.aspx';}";
关于c# - Javascript 在 ASP.NET Web 应用程序中确认框重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7338528/