Wednesday 6 November 2013

How to Get Previous page URL using JQuery or C#/VB.NET in ASP.NET

Hi friends,in this article i will explain about How to Get Previous page URL using JQuery or C#/VB.NET in ASP.NET.
I already explained in the previous articles about JQuery:How to Display Current Date and Time on Webpage using ASP.NET,JQuery : How to show GridView in popup window in ASP.NET,.ready() function in JQuery | $(document).ready() | jQuery Event ready() Method and What is JQUERY | JQuery Tutorial | JQuery syntaxes
In ASP.NET page write the below code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to Get Previous page URL using JQuery or C#/VB.NET in ASP.NET
</title>
   <script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {           
            if (document.referrer.indexOf(window.location.hostname) != -1) {
                var referrer = document.referrer;
                alert(referrer);
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="btn" Text="Get Previous page URL" runat="server"
            onclick="btn_Click"/>
    </div>
    </form>
</body>
</html>

In C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class GetPreviousPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.UrlReferrer != null)

            Response.Write(Request.UrlReferrer.ToString());
    }  
}
In VB.net:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Public Class GetPreviousPage
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Request.UrlReferrer IsNot Nothing Then
            Response.Write(Request.UrlReferrer.ToString())
        End If
    End Sub
End Class

The output of the above page as shown in the below figure.If you click on the Get Previous Page URL if may get present URL.

"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook pageAspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog  for more articles."

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.