Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have tried to redirect a selected value using the below code and it does not work for me..

Any suggestions are highly appreciated.

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if(DropDownList1.SelectedValue=="Exclusive Content")
    {
        Response.Redirect("http://professionaldirect.microsoft.com")
    }
    else if(DropDownList1.SelectedValue=="PDM Availibility")
    {
        Response.Redirect("https://expert.partners.extranet.microsoft.com/userprofile/")
    }
    else if(DropDownList1.SelectedValue=="Windows Azure Help")
    {
        Response.Redirect("http://www.windowsazure.com/en-us/manage/windows/")
    }

}



Regards,
Srinath Patil
Posted
Comments
Srinath Patil 9-Feb-13 10:19am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList1.SelectedValue=="Exclusive Content")
{
Response.Redirect("http://professionaldirect.microsoft.com?Value="+DropDownList1.SelectedValue)
}
else if(DropDownList1.SelectedValue=="PDM Availibility")
{
Response.Redirect("https://expert.partners.extranet.microsoft.com/userprofile/?value="+DropDownList1.SelectedValue)
}
else if(DropDownList1.SelectedValue=="Windows Azure Help")
{
Response.Redirect("http://www.windowsazure.com/en-us/manage/windows/?Value="+DropDownList1.SelectedValue)
}

}
}
}

Add AutoPostBack="true" in your DropDownList aspx code. Like this ..

ASP.NET
<asp:dropdownlist id="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged" autopostback="true" xmlns:asp="#unknown">
      <asp:listitem text="-----Select-----" value="0"></asp:listitem>
</asp:dropdownlist>



-- Updated Answer
Your camparison is wrong. For the below dropdown value

DropDownList1.SelectedText would be "Exclusive Content"
whereas
DropDownList1.SelectedValue would be "http://professionaldirect.microsoft.com"

ASP.NET
<asp:ListItem Text="Exclusive Content" Value="http://professionaldirect.microsoft.com">


Try changing this
C#
if(DropDownList1.SelectedText=="Exclusive Content") 
{ 
   Response.Redirect("http://professionaldirect.microsoft.com?Value="+DropDownList1.SelectedText) 
}
 
Share this answer
 
v2
Comments
Srinath Patil 10-Feb-13 3:56am    
I had set the autopushback to true.. that still does not work.

Both aspx and backed code posted here:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.WebForm1" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Professional Direct Support


<p>Professional Direct Subscription Benefits</p>

<P>Access to this website is exlusive to PDM's and PD customers</P>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Exclusive Content" Value = "http://professionaldirect.microsoft.com">
<asp:ListItem Text="PDM Availibility" Value="https://expert.partners.extranet.microsoft.com/userprofile/">
<asp:ListItem Text= "Windows Azure Help" Value ="http://www.windowsazure.com/en-us/manage/windows/>"


</div>
</form>
</body>
</html>

Backed end code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList1.SelectedValue=="Exclusive Content")
{
Response.Redirect("http://professionaldirect.microsoft.com?Value="+DropDownList1.SelectedValue)
}
else if(DropDownList1.SelectedValue=="PDM Availibility")
{
Response.Redirect("https://expert.partners.extranet.microsoft.com/userprofile/?value="+DropDownList1.SelectedValue)
}
else if(DropDownList1.SelectedValue=="Windows Azure Help")
{
Response.Redirect("http://www.windowsazure.com/en-us/manage/windows/?Value="+DropDownList1.SelectedValue)
}

}
}
}
[no name] 10-Feb-13 4:04am    
Your comparison is wrong. I have updated my answer, check now.
Hi,

In your ASP.NET file (.aspx file), add AutoPostBack="true" to the ASP.NET tag of your drop down list.

Hope this helps.
 
Share this answer
 
Comments
Srinath Patil 10-Feb-13 3:56am    
I had set the autopushback to true.. that still does not work.

Both aspx and backed code posted here:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.WebForm1" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

Professional Direct Support


<p>Professional Direct Subscription Benefits</p>

<P>Access to this website is exlusive to PDM's and PD customers</P>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Exclusive Content" Value = "http://professionaldirect.microsoft.com">
<asp:ListItem Text="PDM Availibility" Value="https://expert.partners.extranet.microsoft.com/userprofile/">
<asp:ListItem Text= "Windows Azure Help" Value ="http://www.windowsazure.com/en-us/manage/windows/>"


</div>
</form>
</body>
</html>

Backed end code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList1.SelectedValue=="Exclusive Content")
{
Response.Redirect("http://professionaldirect.microsoft.com?Value="+DropDownList1.SelectedValue)
}
else if(DropDownList1.SelectedValue=="PDM Availibility")
{
Response.Redirect("https://expert.partners.extranet.microsoft.com/userprofile/?value="+DropDownList1.SelectedValue)
}
else if(DropDownList1.SelectedValue=="Windows Azure Help")
{
Response.Redirect("http://www.windowsazure.com/en-us/manage/windows/?Value="+DropDownList1.SelectedValue)
}

}
}
}
Thomas Daniels 10-Feb-13 4:27am    
Sheikh Muhammad Haris is right. Your comparison is wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900