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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
 function Redirect(sTargetPageURL)
  {
          window.location.href = sTargetPageURL + "?previousPage=" +document.URL;
   }

 </script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" runat="server" value="Redirect" onclick="Redirect('Redirect.aspx');" />
</div>
</form>
</body>
</html>

Please do not post any spam link in the comment box😊

Post a Comment (0)
Previous Post Next Post