Click here to Skip to main content
16,018,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends ,

How to handle control focus on when click tab. In my form when i am clicked a tab , sometimes the focus gone to the master page logo. I have list of textbox controls in next next rows.

I used TabIndex property also in each control. But , no use. Please suggests me any solution. Your help will be appreciate very much. Thanks for advance.
Posted
Comments
Suvendu Shekhar Giri 6-Jan-15 7:00am    
TabIndex should work. The focus will reset to starting TabIndex if any postback occurs. In that case, you need to set the focus to the control from codebehind. If you need code to set focus on control from code behind, please let me know :)
Member 11307706 12-Jan-15 23:42pm    
Hello suvendu, you are absolutely right. Some postback was occurred, so far, i get that problem. I resolved the problem now. Thanks for your valuable comments..
Kumar Pankaj Verma 7-Jan-15 12:43pm    
set it from code side using control.focus();
Member 11307706 12-Jan-15 23:42pm    
OK Sure kumar. Thanks for your comments

1 solution

Hi friends ,

I have resolved myself in above question. I that case , the postback is occurred in some cases. This is the only reason my TabIndex property why was not work ? now , My TabIndex working properly. Additionally , I am add some control focus after postback was occurred. The following code was i am used after focusing.


C#
if (IsPostBack)
      {
          Control ctrl = GetControlThatCausedPostBack(this.Page);

          if (ctrl != null)
              ctrl.Focus();
      }



C#
/// <summary>
    /// Retrieves the control that caused the postback.
    /// </summary>
    /// <param name="page"></param>
    /// <returns></returns>
    private Control GetControlThatCausedPostBack(Page page)
    {
        //initialize a control and set it to null
        Control ctrl = null;

        //get the event target name and find the control
        string ctrlName = page.Request.Params.Get("__EVENTTARGET");
        if (!String.IsNullOrEmpty(ctrlName))
            ctrl = page.FindControl(ctrlName);

        //return the control to the calling method
        return ctrl;
    }


Thanks for all of your valuable comments..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900