Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to redirect to another page from a dropdown list selection

Posted on 2004-08-10
12
Medium Priority
?
267 Views
Last Modified: 2010-04-17
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;
            }

      }
      
      
      

      }




      

      

0
Comment
Question by:dmullis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 3

Expert Comment

by:thecode101
ID: 11765014
I don't know if this will work for you but this script works for me:
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
   if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<form name="form1">
<select name="var" id="var" onChange="MM_jumpMenu('self',this,1)">
<option value="newpage.html">New Page</option>
<option value="newpage2.html">New Page2</option>
</select>
</form>
</body>
0
 

Author Comment

by:dmullis
ID: 11765052
I don't think I can put HTML or Javascript in a .cs page.
0
 
LVL 7

Expert Comment

by:suramsureshbabu
ID: 11765236
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?"};
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:vbnik
ID: 11765294
Try to add "using System.Web"
0
 

Author Comment

by:dmullis
ID: 11765404
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?
0
 

Expert Comment

by:vbnik
ID: 11765545
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.
0
 

Author Comment

by:dmullis
ID: 11765629
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.
0
 

Author Comment

by:dmullis
ID: 11766648
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.Response.Redirect("http://localhost/pltp/Pages/OldVehicles.aspx");
                        }                  
                  }
            }
                  



0
 

Author Comment

by:dmullis
ID: 11766709
Oops. I accidentally sent the page above before I mean too. I added Using System.web and this code:

 if (i== 1)
                         
                    {
                         
                         HttpContext.Current.Response.Redirect("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?            


0
 
LVL 7

Accepted Solution

by:
jacobhoover earned 2000 total points
ID: 11768676
You should be able to handle the event on the server side with:

In Page_Load:

ddlLocation.SelectedIndexChanged += new System.EventHandler(this.ddlLocationSelectedIndexChanged);

Then create your own handler in the class:

protected void ddlLocationSelectedIndexChanged(Object sender , System.EventArgs e)
{
  If ddlLocation.SelectedItem.Value = "CA"  Server.Transfer("http://localhost/CA/Index.aspx");
  If ddlLocation.SelectedItem.Value = "WI"  Server.Transfer("http://localhost/WI/Index.aspx");
}

P.S.
  Tis is all done in the CS file and you need to put AutoPostBack="True" on the dropdownlist or have a submit button the user clicks.
0
 

Author Comment

by:dmullis
ID: 11773355
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.
0
 

Author Comment

by:dmullis
ID: 11775023
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question