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

RadTextbox loses focus on AutoPostback in a usercontrol

3 Answers 285 Views
Input
This is a migrated thread and some comments may be shown as answers.
saritha78
Top achievements
Rank 1
saritha78 asked on 08 Mar 2011, 11:44 PM
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)
        {
            rdAjaxManager.FocusControl(rdtAddr1);
        }
    }

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 14 Mar 2011, 08:14 AM
Hi,

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.

Greetings,
Tsvetina
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!
0
Syed
Top achievements
Rank 1
answered on 23 Nov 2013, 12:05 PM
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;
                else
                    Eqt = Convert.ToDecimal(Entqt);

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

                Com.CommandType = CommandType.StoredProcedure;
                Com.CommandText = "tempTREEVIEW_ASSIGN_SUM_PREPARE_CLAIM";
                Com.Parameters.Clear();
                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");
                else
                    Com.Parameters.AddWithValue("@Subcontractor", Subcontractor.SelectedValue);
                Com.Parameters.AddWithValue("@SubProjRefNo", SubprojRefNo1);
                int recs = Com.ExecuteNonQuery();


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

regards

Hussain
0
Viktor Tachev
Telerik team
answered on 27 Nov 2013, 03:38 PM
Hello,

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.

Regards,
Viktor Tachev
Telerik
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.
Tags
Input
Asked by
saritha78
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Syed
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or