views:

108

answers:

3

I have a telerik radgrid that has an allows inserts. After clicking the "Add New Record" button the textboxes appear with a couple of buttons. One for Insert and one to cancel. I would like the page focus to be on the insert button so when the user clicks the enter button, the insert button has the focus.

Does anyone know how to do this?

A: 

Conceptually, it should be possible.

The Add New Record button causes a postback, from my recollection. In that postback, hook into the RadGrid's corresponding event and inject javascript to focus the button.

If you define the edit form through a template, you may also be able to get away with it by using the DefaultButton property on a panel that wraps the editor controls.

I do also agree with Claudio, that Telerik support is great. You may want to start with them as they'll likely give you a complete code sample accomplishing your task.

KP
+1  A: 

This isn't tested but I'd assume you'd do it on the ItemCreated event:

Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)
    If TypeOf e.Item Is GridCommandItem Then

        Dim myButton As LinkButton = TryCast(e.Item.FindControl("myButtonID"), LinkButton)
        myButton.Focus()
    End If
End Sub
Markive
Also if it isn't the ItemCreated event then it's probably ItemDataBound
Markive
A: 

I found the answer and it is almost like what Markive has, here is the c# version, I am using a ImageButton instead of a LinkButton:

        protected void gvApplications_ItemDataBound(object sender, GridItemEventArgs e)
    {
        //when a user clicks the "Add New" button, 
        //this code puts focus on the Insert button so when the enter key is clicked, the action occurs
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
            ImageButton btnInsert = (ImageButton)insertItem.FindControl("PerformInsertButton");
            btnInsert.Focus();
        }
    }
RJ