Home Asp.net Redirect Page on Button Click in Asp.net using JavaScript jQuery

Redirect Page on Button Click in Asp.net using JavaScript jQuery

105
0
Redirect Page on Button Click

In my previous tutorials, I’d explained how to auto-refresh webpage in every 10 seconds, how to auto-redirect to a specific url or webpage in 10 seconds, gridview inline insert update delete, and other more cracking tutorials on Asp.net, JavaScript, jQuery here.

Now here in this tutorial, I’ll explain how to redirect to a specific webpage or a URL on button click event from client-side using JavaScript or jQuery in asp.net.

Following is the code snippet that is use to redirect a specific webpage on button click event using JavaScript or jQuery.

Redirect Page on Button Click – [JavaScript]

<script type="text/javascript">
    //Method using JavaScript
    function Redirect() {
        //specify your URL here..
        window.location.href = '/AutoRefreshWebPage.aspx';
    }
</script>

Redirect Page on Button Click – [jQuery]

<script type="text/javascript">
    //Method using jQuery
    $(document).ready(function () {
        $("#btnRedirectUsingjQuery").click(function () {
            //specify your URL here..
            window.location.href = '/AutoRefreshWebPage.aspx';
        });
    });
</script>

HTML Markup for Redirect webpage – [.aspx]

Following is the complete HTML Markup code to redirect a webpage or url on a button click event:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Redirect to another webpage on button click event</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
        //Method using jQuery
        $(document).ready(function () {
            $("#btnRedirectUsingjQuery").click(function () {
                //specify your URL here..
                window.location.href = '/AutoRefreshWebPage.aspx';
            });
        });

        //Method using JavaScript
        function Redirect() {
            //specify your URL here..
            window.location.href = '/AutoRefreshWebPage.aspx';
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        <br />
        <br />
        <input id="btnRedirectUsingJavascript" value="Redirect Using JavaScript" type="button"
            onclick="Redirect()" />
        &nbsp;&nbsp;
        <input id="btnRedirectUsingjQuery" value="Redirect Using jQuery" type="button" />
        </div>
    </form>
</body>
</html>

Download Example

Git Repo

That’s it, by using this way you Redirect Page on Button Click event in javascript or jquery using Asp.net web page.

Let me know if you’ve any questions or doubts about this tutorial by writing down your queries in comment below. I would be happy to provide you my feedback as soon as possible.

Happy coding!

Previous articleAutomatically Redirect a Web Page or URL after 5 Seconds in Asp.net
Next articlejQuery fading Effects – fadeIn fadeOut fadeTo fadeToggle to DIV text
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

sixteen − three =