How To Redirect User To Another Page using JavaScript and Access The URL Property In Code Behind.

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
 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>

Reactions

Post a Comment

3 Comments

  1. I have sweaty balls now

    Ioana Mocanu
    ASP Bucharest, Romania

    ReplyDelete
  2. but how can i redirect the same with the . plz suggest.

    ReplyDelete

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

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)

Close Menu