RadTextbox loses focus on AutoPostback in a usercontrol

4 posts, 0 answers
  1. saritha78
    saritha78 avatar
    23 posts
    Member since:
    Dec 2009

    Posted 08 Mar 2011 Link to this post

    I have a user control with some RadTextboxes, RadNumericTextboxes, RadComboBoxes. I have this usercontrol on an aspx page which has the RadAjaxManager. I have a requirement to maintain if the controls in the usercontrol have changes, so, I have set the AutoPostBack property to true and on postback, I set ViewState["NameIsDirty"]=true; But my problem is, when the user updates the Name and clicks on tab, the cursor goes to the next control and immediately disappears! Seems like it is getting focussed on the first control on the page. If I dont have the AutoPostBack property set to true, the focus is on the next control and everything is fine. How do I make the focus stay on the control on which it is supposed to be. I searched the forums and tried a few solutions, but they did not work.
    I have tried this and it doesnt work:
    protected void rdtCCno_TextChanged(object sender, EventArgs e)
            ViewState["NumberIsDirty"] = true;
            string script =string.Format(@"window.setTimeOut(function(){{$find('{0}').Focus();}},10);",rdtCvv2.ClientID);
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "mykey", script,true);
        protected void rdcExpMonth_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
            ViewState["ExpMonthIsDirty"] = true;
            var rdAjaxManager = RadAjaxManager.GetCurrent(this.Page);
            if (rdAjaxManager != null)
  2. Tsvetina
    Tsvetina avatar
    2085 posts

    Posted 14 Mar 2011 Link to this post


    Since the mentioned controls are composite ones, you should set the focus to the correct input. For example, for a RadTextBoxes this would be:
    RadAjaxManager1.FocusControl(RadInput1.ClientID + "_text")

    And for a RadComboBox:
    RadAjaxManager1.FocusControl(RadComboBox1.ClientID + "_Input");

    This way the FocusControl() method of the ajax manager should work.

    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Syed
    Syed avatar
    3 posts
    Member since:
    Nov 2013

    Posted 23 Nov 2013 Link to this post

    This is What I am doing in Text changed That inside RadTreeList , When Finished Text changed it need to go for Next Control But it Going Out of Focus , and in this I have More than One Row in RadTreeList  How can Get particular Row th Control Id

    Control Version is 2011.1.519.40

    Please Help ME

    protected void EntQntyId_TextChanged(object sender, EventArgs e)
                //RadTreeListWork.ClientSettings.Scrolling.UseStaticHeaders = 1;

                foreach (TreeListDataItem item in RadTreeListWork.Items)
                    int? id = (int?)item.GetDataKeyValue("WorkId");
                    double? Entqt = (item["EnterQuantity"].FindControl("EntQntyId") as RadNumericTextBox).Value;
                    //double? Balqt = (item["BalanceQty"].FindControl("BalQnty2") as RadNumericTextBox).Value;
                    string Remrk = (item["Remarkss"].FindControl("TextRemarks") as RadTextBox).Text;

                    decimal Eqt;
                    //decimal Bqt;
                    if (Entqt == null)
                        Eqt = 0;
                        Eqt = Convert.ToDecimal(Entqt);

                    catch (Exception sl)
                    { Globals.makecon(ref Con, ref Com, ref da1); }

                    Com.CommandType = CommandType.StoredProcedure;
                    Com.CommandText = "tempTREEVIEW_ASSIGN_SUM_PREPARE_CLAIM";
                    Com.Parameters.AddWithValue("@ProjectCode", projcode);
                    Com.Parameters.AddWithValue("@workid", id);
                    Com.Parameters.AddWithValue("@entqnty", Eqt);
                    //Com.Parameters.AddWithValue("@balqnty", Bqt);
                    Com.Parameters.AddWithValue("@COUNT", 1);
                    Com.Parameters.AddWithValue("@REMARKS", Remrk);
                    if (Subcontractor.SelectedValue == "-1" && Subcontractor.SelectedValue == "")
                        Com.Parameters.AddWithValue("@Subcontractor", "0");
                        Com.Parameters.AddWithValue("@Subcontractor", Subcontractor.SelectedValue);
                    Com.Parameters.AddWithValue("@SubProjRefNo", SubprojRefNo1);
                    int recs = Com.ExecuteNonQuery();

                    RadAjaxManager1.FocusControl(RadTreeListWork.ClientID + "_text");


  4. Viktor Tachev
    Viktor Tachev avatar
    1767 posts

    Posted 27 Nov 2013 Link to this post


    In order to focus a control with FocusControl() method you need to pass id or reference of the control that should be focused.

    In your code it seems that "RadTreeListWork" is the ID of the RadTreeList control and not a TextBox control. Try passing the ID of the control that you would like to be focused in OnTextChanged and you should get the behavior you are looking for.

    Note that since Q3 2011 RadInput uses new rendering mode where only one input element of type text is used. If you have version later than the mentioned you should use only the ID of the control that should be focused, without "_text", as explained in this article.

    It is recommended to upgrade to the latest version of RadControls as it includes new features and improvements to the controls.

    Viktor Tachev
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top