This is a migrated thread and some comments may be shown as answers.

combobox

1 Answer 57 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rathan
Top achievements
Rank 1
Rathan asked on 18 Jun 2012, 09:16 AM
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. 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jun 2012, 10:37 AM
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.
Tags
ComboBox
Asked by
Rathan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or