Description:-
In this Example we
explain that how to Fetch previous page URL in Asp.Net using jquery and C#. or
how to get previous page URL in asp.netweb
application project.
Sometime we have requirement to redirect the user to the previous page or transfer user to the previous page in our application. For example if user is travel from one page to another page and if in second page that's have no writes then we all generally redirect or transfer user to Login.aspx page but sometime requirement if user have no rights then it's redirect to the previous page in which he travel to this page.
Sometime we have requirement to redirect the user to the previous page or transfer user to the previous page in our application. For example if user is travel from one page to another page and if in second page that's have no writes then we all generally redirect or transfer user to Login.aspx page but sometime requirement if user have no rights then it's redirect to the previous page in which he travel to this page.
To show Example How to insert,update,delete in DataList control clikck here CRUD operation in DataList
How to Bind Excelsheet Data to Gridview CRUD operation in Excelsheet Database
So perform this type of condition or flow follow the below code
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title> Get
Previous page URL in asp.net using JQuery
</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>
<b>click below
button to fetch previous page url</b>
<asp:Button ID="btnpreviouspageurl" Text="Get Previous page URL"
runat="server"
/>
</div>
</form>
</body>
</html>
Default3.aspx.cs:-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using System.Data;
using
System.Data.SqlClient;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
if
(Request.UrlReferrer != null)
Response.Write(Request.UrlReferrer.ToString());
}
}
}
0 comments:
Post a Comment