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

Set Focus on Popup Edit Form

6 Answers 238 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pbreck
Top achievements
Rank 1
pbreck asked on 11 Mar 2010, 06:58 PM

I’ve been trying to set focus on a DropdownList input cell in a Popup edit form.  I tried putting code on the ItemDataBound event without much luck.  
I was wondering if using the “Grid / PopUp Edit Form” http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/popupeditform/defaultcs.aspx example someone could show me how to set focus on the “Title Of Courtesy” dropdown field when in edit mode.   At the very least I’d like to see how to set focus on the Popup Edit form itself.  Thanks.

6 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 12 Mar 2010, 09:46 AM
Hello Pbreck,

I would suggest you to try the following approach:

protected void MyGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditFormItem form = (GridEditFormItem)e.Item;
                DropDownList list = form.FindControl("MyDropDownID") as DropDownList;
                list.Focus();
            }
        }

You can also check this help article:

Focus the text boxes in the edit control

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
pbreck
Top achievements
Rank 1
answered on 17 Mar 2010, 03:28 AM

I tried both solutions ( "attach to the ItemDataBound event handler" and "adds a literal control to Telerik RadGrid, containing JavaScript code" ) in the link http://www.telerik.com/help/aspnet-ajax/grdsetfocusontextboxesineditcontrol.html  and neither one sets focus on the POPUP edit control.  I'm using the baked in auto edit form (not a template). 

I also found a discussion in thread  http://www.telerik.com/community/forums/aspnet-ajax/grid/popup-edit-form-setting-focus-error.aspx and the last response shows using a template.  I tried this template and it worked but of course I only ended up with the single numeric text box.   

Will focus work with the automatically generated edit Popup form?  

I don't want to manually create my popup edit control in a FormTemplate section of my aspx file.  Right now all my fields are databound and inserts and updates are working fine.
 

                    <FormTemplate> 

                       <telerik:RadNumericTextBox ID="TextBox1" Value="1" runat="server" /> 

                    </FormTemplate> 

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  

    {  

        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  

        {  

            GridEditFormItem item = (GridEditFormItem)e.Item;  

            RadNumericTextBox txtBox = item.FindControl("TextBox1"as RadNumericTextBox;  

            txtBox.SelectionOnFocus = SelectionOnFocus.SelectAll;  

            txtBox.Focus();  

        }  

    }  

 

 

 

 

 

 

0
pbreck
Top achievements
Rank 1
answered on 17 Mar 2010, 08:18 PM

I was able to get it to work by changing the EditMode="Editforms" instead of "Popup" in the aspx file.   In the aspx.cs file I added the following code to the ItemCreated event.

 


if
(e.Item is GridEditFormItem && e.Item.IsInEditMode)

{

 

    GridEditFormItem item = (GridEditFormItem)e.Item;

 

 

    DropDownList list = (item as GridEditableItem)["PartTypeDropDown"].Controls[0] as DropDownList;

 

    list.Focus();

}

 

 

Still would like to know how to get this to work with EditMode="Popup".  Thanks

0
Martin
Telerik team
answered on 19 Mar 2010, 06:06 PM
Hello Pbreck,

I have created a small sample project demonstrating how to achieve the desired functionality. Give it a try and let me know how it goes on your side.

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
NetDeveloper
Top achievements
Rank 1
answered on 07 Apr 2010, 06:49 PM
I have been having the same issue setting focus on an Edit Pop up form.  I tried to implement the solution found in the attached files and I was getting the following error:

"htmlfile: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

Also, a difference between the solution file and my code is that I am using a FormTemplate for the EditForm. 

0
Martin
Telerik team
answered on 13 Apr 2010, 07:17 AM
Hello CRodabaugh,

I have attached a modified version of the sample project that runs as expected on my side. Please give it a try and let me know how it goes.

Regards,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
pbreck
Top achievements
Rank 1
Answers by
Martin
Telerik team
pbreck
Top achievements
Rank 1
NetDeveloper
Top achievements
Rank 1
Share this question
or