dmullis
asked on
Need to redirect to another page from a dropdown list selection
I have a server control called StateList.cs. It renders a dropdown menu on the webpage with 2 choices, CA and FL. If the user clicks on CA in the list, I need to redirect him to another web page. ( aspx\html) I tried using Responce. Redirect but it kept telling me it was not defined, etc. I am not sure how to do this. The entire code is below:
using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aon.Pltp.BusinessServices;
namespace Aon.Pltp.ServerControls
{
///<copyright>
/// (c) 2002 Aon Services Group, Inc. All Rights Reserved.
///</copyright>
/// <summary>
/// Summary description for StateList.
/// </summary>
public class StateList : DropDownList
{
public StateList()
{
//Set drop down width
this.Width = 48;
//set item value and item text
string[] elements = {"CA", "FL"};
//Add item to list item
for (int i = 0;i < elements.GetLength(0);i++)
{
this.Items.Add(new ListItem(elements[i]));
}
}
// TODO: This code is probably leftover from an earlier test that was never deleted.
// Should experiment with commenting it out.
public DropDownList StateSpecificlist()
{
//Set drop down width
this.Width = 48;
DropDownList dd = new DropDownList();
//set item value and item text
User user = BusinessServices.UserState .getUser() ;
string state = user.RegionID.ToUpper();
string element = state;
//Add item to list item
dd.Items.Add(element);
return dd;
}
}
}
using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aon.Pltp.BusinessServices;
namespace Aon.Pltp.ServerControls
{
///<copyright>
/// (c) 2002 Aon Services Group, Inc. All Rights Reserved.
///</copyright>
/// <summary>
/// Summary description for StateList.
/// </summary>
public class StateList : DropDownList
{
public StateList()
{
//Set drop down width
this.Width = 48;
//set item value and item text
string[] elements = {"CA", "FL"};
//Add item to list item
for (int i = 0;i < elements.GetLength(0);i++)
{
this.Items.Add(new ListItem(elements[i]));
}
}
// TODO: This code is probably leftover from an earlier test that was never deleted.
// Should experiment with commenting it out.
public DropDownList StateSpecificlist()
{
//Set drop down width
this.Width = 48;
DropDownList dd = new DropDownList();
//set item value and item text
User user = BusinessServices.UserState
string state = user.RegionID.ToUpper();
string element = state;
//Add item to list item
dd.Items.Add(element);
return dd;
}
}
}
ASKER
I don't think I can put HTML or Javascript in a .cs page.
try out putting hyperlink along with the name of the state in teh array list
string[] elements = {"<a href='CA.html'>CA</a>", "<a href='FL.html'>FL</a?"};
string[] elements = {"<a href='CA.html'>CA</a>", "<a href='FL.html'>FL</a?"};
Try to add "using System.Web"
ASKER
I've added System. Web and I still can't get anything to work.
I also tried string[] elements = {"<a href='CA.html'>CA</a>", "<a href='FL.html'>FL</a?"};
It literally puts all that info in the dropdown menu.
Any other ideas?
I also tried string[] elements = {"<a href='CA.html'>CA</a>", "<a href='FL.html'>FL</a?"};
It literally puts all that info in the dropdown menu.
Any other ideas?
On a form where you put your control write something like this (My syntax is more like VB)
If MyControl.SelectedItem = 0 then Response.Redirect ( 'CA.html')
Else Response.Redirect ('FL.html')
end
It looks like your control does not know what HttpResponse object is.
If MyControl.SelectedItem = 0 then Response.Redirect ( 'CA.html')
Else Response.Redirect ('FL.html')
end
It looks like your control does not know what HttpResponse object is.
ASKER
I'm still having trouble with it. I am so new to C# and programing in general, it's probably something simple I'm doing or not doing. I didn't write this page. You are right ,It does not seem to recognise the HttpResponse object though.
I tried if Statelist.Elements but it didn't like it.
I tried if Statelist.Elements but it didn't like it.
ASKER
using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aon.Pltp.BusinessServices;
System. Web
namespace Aon.Pltp.ServerControls
{
///<copyright>
/// (c) 2002 Aon Services Group, Inc. All Rights Reserved.
///</copyright>
/// <summary>
/// Summary description for StateList.
/// </summary>
public class StateList : DropDownList
{
public StateList()
{
//Set drop down width
this.Width = 48;
//set item value and item text
string[] elements = {"CA", "FL"};
//Add item to list item
for (int i = 0;i < elements.GetLength(0);i++)
{
this.Items.Add(new ListItem(elements[i]));
if (i== 1)
{
HttpContext.Current.Respon se.Redirec t("http://localhost/pltp/Pages/OldVehicles.aspx");
}
}
}
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aon.Pltp.BusinessServices;
System. Web
namespace Aon.Pltp.ServerControls
{
///<copyright>
/// (c) 2002 Aon Services Group, Inc. All Rights Reserved.
///</copyright>
/// <summary>
/// Summary description for StateList.
/// </summary>
public class StateList : DropDownList
{
public StateList()
{
//Set drop down width
this.Width = 48;
//set item value and item text
string[] elements = {"CA", "FL"};
//Add item to list item
for (int i = 0;i < elements.GetLength(0);i++)
{
this.Items.Add(new ListItem(elements[i]));
if (i== 1)
{
HttpContext.Current.Respon
}
}
}
ASKER
Oops. I accidentally sent the page above before I mean too. I added Using System.web and this code:
if (i== 1)
{
HttpContext.Current.Respon se.Redirec t("http://localhost/pltp/Pages/OldVehicles.aspx");
}
This code redirects the page the second it's loaded. It doesn't wait for a dropdown selectin to be clicked. the entire code is above. Any ideas on how to only have it redirect when the value is selected?
if (i== 1)
{
HttpContext.Current.Respon
}
This code redirects the page the second it's loaded. It doesn't wait for a dropdown selectin to be clicked. the entire code is above. Any ideas on how to only have it redirect when the value is selected?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi jacobhover. I am going to attempt doing this with javascript on an XML page as someone suggested at my work first, then if no go, come back to your suggestion. It appears what you wrote above is what I may be looking for.
ASKER
jacobhover,
I was actually able to use javascript this time but this is definitely something I need to know how to do. I am going to print out and save for future reference.
I was actually able to use javascript this time but this is definitely something I need to know how to do. I am going to print out and save for future reference.
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,re
eval(targ+".location='"+se
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<form name="form1">
<select name="var" id="var" onChange="MM_jumpMenu('sel
<option value="newpage.html">New Page</option>
<option value="newpage2.html">New Page2</option>
</select>
</form>
</body>