UpdatePanel and Textbox Focus

Last post 05-08-2008 12:33 PM by jweightman. 1 replies.

Sort Posts:

  • UpdatePanel and Textbox Focus

    05-07-2008, 1:36 PM
    • Member
      20 point Member
    • jweightman
    • Member since 12-26-2002, 7:54 AM
    • Posts 10

     I have a page with an UpdatePanel and inside the UpdatePanel there is a TabContainer. The content of each TabPanel is a different User Control. I am trying to set the focus on a specific textbox on one of the TabPanels/user controls, but cannot currently get it to work. I am wondering if anyone has been successful in doing something similar ?

     

    Thanks,

    Jim  

  • Re: UpdatePanel and Textbox Focus

    05-08-2008, 12:33 PM
    Answer
    • Member
      20 point Member
    • jweightman
    • Member since 12-26-2002, 7:54 AM
    • Posts 10

     I eventually managed to get something working.  So, in case someone else has a similar problem, here is what I did:

    - In the Page_Load of the user control I pass back the ClientID of the textbox like this : 

    ScriptManager.RegisterClientScriptBlock(this, GetType(), "txtSearchBarcode", "var _txtSearchBarcode = '" + txtSearchBarcode.ClientID + "';", true);
     

     Then on the main page(which contains the Tab Container), I added this javascript:

            function getControl_TabClicked2(sender, e) {   
    control = $get(_txtSearchBarcode);
    }
    function setFocus(sender, e) {
    try{
    control.focus();
    }
    catch(e){
    //do nothing
    }
    }

     The Tab Container line looks like this :

    <cc1:TabContainer ID="tcMain" runat="server" CssClass="ajax__tab_yuitabview-theme" OnClientActiveTabChanged="setFocus">
     

    And finally the specific TabPanel :

    <cc1:TabPanel ID="tcSearch" runat="server" HeaderText="Search" OnClientClick="getControl_TabClicked2">
     This is an amalgamation of a few different solutions I found on the net, hopefully it will help someone else.
    Cheers,
    Jim 
      

     

     

Page 1 of 1 (2 items)