2

I am using this code block from a previous SO post showing ClientScript Alerts before Redirecting to another page in ASP.NET c#? that will display an alert message in an aspx page before redirecting to another page. I modified this script to avoid the redirect part.

However, this page does a submit. How can I avoid doing a page submit?

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.");
4

2 回答 2

3

您可以添加return false;到您的代码

<script language='javascript'>instructions ....; return false; </script>
于 2012-10-12T10:01:09.723 回答
0

如果你想在任何按钮上调用它,那么你可以这样做:Javascript代码

$('[id$=btntest]').live('click',function(e){
    e.preventdefault();
    });

或者你也可以像下面那样做

 $('[id$=btntest]').live('click',function(e){
    return false;
    });
于 2012-10-12T10:47:28.073 回答