mmalik15
asked on
how to redirect in aspx page in c#
I need to redirect a page to another page directly on the server. i.e. any request to this page
http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx?ContainerID=200298
should go to http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx
I can't make change in the .cs file. I am trying to add something like this in aspx file but no luck
<%
if (!String.IsNullOrEmpty(Req uest.Query String["Co ntainerID" ]))
{
var x = Request.QueryString["Conta inerID"].T oString();
if (x == "200298")
Response.Redirect("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
}
%>
http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx?ContainerID=200298
should go to http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx
I can't make change in the .cs file. I am trying to add something like this in aspx file but no luck
<%
if (!String.IsNullOrEmpty(Req
{
var x = Request.QueryString["Conta
if (x == "200298")
Response.Redirect("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
}
%>
ASKER
sorry it does not work I have tried the following
<%@ Page language="c#" Codebehind="Index.aspx.cs" AutoEventWireup="false" Inherits="nes.SharedSpace. Pages.Inde x" %>
<%
if (!String.IsNullOrEmpty(Req uest.Query String["Co ntainerID" ]))
{
var x = Request.QueryString["Conta inerID"].T oString();
if (x == "200298")
Server.Transfer("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
}
%>
and when I click on http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx?ContainerID=200298 I get a blank page
<%@ Page language="c#" Codebehind="Index.aspx.cs"
<%
if (!String.IsNullOrEmpty(Req
{
var x = Request.QueryString["Conta
if (x == "200298")
Server.Transfer("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
}
%>
and when I click on http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx?ContainerID=200298 I get a blank page
ok...so this is inline ASP? as in ASP Classic?
And are you looking at this as part of the page load?
or as part of a change in status to a control on the page?
One more thing:
I tried to navigate to:
http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx
without the ?= element, and that page itself does not load.
Is that page missing?
Thanks
And are you looking at this as part of the page load?
or as part of a change in status to a control on the page?
One more thing:
I tried to navigate to:
http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx
without the ?= element, and that page itself does not load.
Is that page missing?
Thanks
If you can't make a change in the .cs file of your code-behind, why make this a server-side script?
I'm going to assume you are using Javascript for your client script. Replace your <% %> block with:
Alternatively, you can use
I'm going to assume you are using Javascript for your client script. Replace your <% %> block with:
<script type="text/javascript" language="javascript">
if ("<%=Request.QueryString["ContainerID"].ToString()%>" == "200298")
window.navigate("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
</script>
Alternatively, you can use
<script type="text/javascript" language="javascript">
if ("<%=Request.QueryString["ContainerID"].ToString()%>" == "200298")
window.location = "http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx";
</script>
ASKER
My aspx page now have the following markup
<%@ Page language="c#" Codebehind="Index.aspx.cs" AutoEventWireup="false" Inherits="nes.SharedSpace. Pages.Inde x" %>
<script type="text/javascript" language="javascript">
if ("<%=Request.QueryString[" ContainerI D"].ToStri ng()%>" == "200298")
window.navigate("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
</script>
now I am getting an error on the page. Please click on the page to see the exact error
http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx?ContainerID=200298
<%@ Page language="c#" Codebehind="Index.aspx.cs"
<script type="text/javascript" language="javascript">
if ("<%=Request.QueryString["
window.navigate("http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx");
</script>
now I am getting an error on the page. Please click on the page to see the exact error
http://www.elib.scot.nhs.uk/SharedSpace/rehab/Pages/Index.aspx?ContainerID=200298
Let's change it up a bit:
<script type="text/javascript">
var first = getUrlVars()["ContainerID"];
if (first == 200298)
{
window.location.href = 'http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx';
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
</script>
test.html
ASKER
I have changed the script but still getting the last error.
<script type="text/javascript">
var first = getUrlVars()["ContainerID" ];
if (first == 200298)
{
window.location.href = 'http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx';
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.repla ce(/[?&]+( [^=&]+)=([ ^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
</script>
<script type="text/javascript">
var first = getUrlVars()["ContainerID"
if (first == 200298)
{
window.location.href = 'http://www.knowledge.scot.nhs.uk/fallsandbonehealth.aspx';
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.repla
vars[key] = value;
});
return vars;
}
</script>
Check out the file I gave you.
I tested it, and it went to the site as requested.
I tested it, and it went to the site as requested.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Server.Transfer("Webform2.
Instead of Response.Redirect.
See if that helps.