How To Redirect User To Another Page using JavaScript in ASP.NET

When you redirect your page, the Request collection is undefined because you have not requested anything. You can catch your referrer from javascript and the other. The way is to use Querystring in code behind.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JavascriptRedirection.aspx.cs" Inherits="JavascriptRedirection" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
 function Redirect(sTargetPageURL)
          window.location.href = sTargetPageURL + "?previousPage=" +document.URL;

<form id="form1" runat="server">
<input type="button" runat="server" value="Redirect" onclick="Redirect('Redirect.aspx');" />
Next Post Previous Post
No Comment
Add Comment
comment url