1. Rathan
    Rathan avatar
    20 posts
    Member since:
    Oct 2011

    Posted 18 Jun 2012 Link to this post

    Hi,

       This is Rathan . am using comboboxes in my form , set the tab index to combobox but it not working properly .when the selected indexchanged event fired the tabindex automatically focus goes to top control and if am using two comboboxes one by one its not goes to the tab to next combobox . so please  let me know .


    Thank you in advance. 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Jun 2012 Link to this post

    Hi Rathan,

    Try the following code to fix your problem.

    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                WebControl wcICausedPostBack = (WebControl)GetControlThatCausedPostBack(sender as Page);
                int indx = wcICausedPostBack.TabIndex;
                var ctrl = from control in wcICausedPostBack.Parent.Controls.OfType<WebControl>()
                           where control.TabIndex > indx
                           select control;
                ctrl.DefaultIfEmpty(wcICausedPostBack).First().Focus();
            }
        }
        protected Control GetControlThatCausedPostBack(Page page)
        {
            Control control = null;
            string ctrlname = page.Request.Params.Get("__EVENTTARGET");
            if (ctrlname != null && ctrlname != string.Empty)
            {
                control = page.FindControl(ctrlname);
            }
            else
            {
                foreach (string ctl in page.Request.Form)
                {
                    Control c = page.FindControl(ctl);
                    if (c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton)
                    {
                        control = c;
                        break;
                    }
                }
            }
            return control;
        }

    Hope this helps.

    Thanks,
    Princy.
Back to Top