2
votes

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.");
2
if our answers have solved your problem then don't forgot to accept ...... - Ram Singh

2 Answers

3
votes

You can add return false; to your code

<script language='javascript'>instructions ....; return false; </script>
0
votes

if you want to call it on any button then like below you can do it: Javascript code

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

or you can do like below also

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