我正在使用之前 SO 帖子 showing ClientScript Alerts before Redirecting to another page in ASP.NET c#? 中的代码块在重定向到另一个页面之前,它将在 aspx 页面中显示一条警报消息。我修改了这个脚本以避免重定向部分。
但是,此页面会进行提交。如何避免页面提交?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class HTMLHelper
{
public static void jsAlertAndRedirect(System.Web.UI.Page instance, string Message,string url)
{
instance.Response.Write(@"<script language='javascript'>alert('" + Message + "'); </script>");
}
}
HTMLHelper.jsAlertAndRedirect(this, "This is an alert.");
最佳答案
您可以将 return false;
添加到您的代码
<script language='javascript'>instructions ....; return false; </script>
关于javascript - 在 JavaScript 中显示警报消息时避免页面提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12856542/