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.");
1
  • if our answers have solved your problem then don't forgot to accept ...... Commented Oct 12, 2012 at 14:10

2 Answers 2

3

You can add return false; to your code

<script language='javascript'>instructions ....; return false; </script>
Sign up to request clarification or add additional context in comments.

Comments

0

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;
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.