Dropwdown list in IE when using tab

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    Dropwdown list in IE when using tab

    Hello there

    I have a webform which has a dropdown list with the countries names in it. The dropdown list does a autopostback. When I try to fill the form using tab key to move from one controller to other, the dropdown list gives a problem.
    In IE, if I have to select USA, when I tab down to the dropdown list and press U, the first country with U ie Uganda get selected automatically and focus jumps to next control. In firefox this works perfectly. can somebody help me with this..thank you...
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    First of all clear the AutoPostBack field of DropDownList and make the AutoPostBack of Page_Load() also not true. I hope it'll work fine. I made a simple application following the same rule and tab works fine giving no problem.

    Code:
    public class Country
    {
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public Country(string name)
        {
            Name = name;
        }
        public Country()
    	{
    		//
    		// TODO: Add constructor logic here
    		//
    	}
        public static List<Country> GetCountry()
        {
            List<Country> country = new List<Country>();
            country.Add(new Country("India"));
            country.Add(new Country("USA"));
            country.Add(new Country("England"));
            country.Add(new Country("China"));
            country.Add(new Country("bangladesh"));
            country.Add(new Country("Pakistan"));
            country.Add(new Country("France"));
            return country;
        }
    }
    Code:
    public partial class _Default : System.Web.UI.Page 
    {
        private List<Country> country = Country.GetCountry();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = country;
                DropDownList1.DataTextField = "Name";
                DropDownList1.DataValueField = "Name";
                DropDownList1.DataTextFormatString = "Name: {0}";
                DropDownList1.DataBind();
            }
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = DropDownList1.SelectedValue;
        }
    }
    In my page I dragged a DropDownList, a button and a Label. While tabbing, it comes first on DropDownList, second on Button, prssing enter it gives the selected country's name in Label.

    Best of Luck.

    Comment

    • user1980
      New Member
      • Dec 2009
      • 112

      #3
      Thank you for the reply. But I would need to do a post back so that another dropdown populates depending on the selection of the country ddl. so in this case how would I achieve it.

      thank you once again for your time.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Have you considered handling the JavaScript onblur event for the DropDownList and manually doing a postback to the server?

        -Frinny

        Comment

        • sanjib65
          New Member
          • Nov 2009
          • 102

          #5
          Besides trying what Frinavale has said, if I use .NET 3.5, then I'd try LinkDatSource as a common data access layer between these two controls.

          Comment

          Working...