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

[Solved] Setting Focus to a Control

3 Answers 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 26 Mar 2008, 03:54 AM

Hi

I'm trying to set focus to a control when in add or edit mode in a radgrid using the following code I got from reading existing posts.  I'm using automatic binding and in form editing.

radgridTimesheets.ClientSettings.ClientEvents.OnColumnCreated = "setTimeout(function(){document.getElementById('" + radcomboClient_Task.ClientID + "').focus();},200);"

However,  I receive a page error message stating that "Error: Expected '}'" and I cant see where I'm going wrong as the code looks OK to me.

Thanks

Richard

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 28 Mar 2008, 09:44 AM
Hello Richard,

Could you please give us more details about this code? For example where do you place it, and is the combo inside or outside the grid? The implementation seems correct and unfortunately I cannot say for certain what might cause this erroneous behavior.

Best regards,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Richard
Top achievements
Rank 1
answered on 28 Mar 2008, 12:09 PM
Iana

It is in the onselectedindex changed event for a template radcombo control.  See the code below.

Thanks

Richard


Public Sub radcomboClientEntry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

'first reference the edited grid item through the NamingContainer attribute

Dim editedItem As GridEditableItem = CType(CType(sender, RadComboBox).NamingContainer, GridEditableItem)

' set the value of the client task combo

Dim radcomboClient As RadComboBox = CType(editedItem("Client_ID").FindControl("radcomboClientEntry"), RadComboBox)

Dim radcomboClient_Task As RadComboBox = CType(editedItem("Client_Task_ID").FindControl("radcomboClient_Task"), RadComboBox)

' set the value of the client task combo

radcomboClient_Task.Items.Clear()

dsClient_Tasks.SelectParameters(0).DefaultValue = radcomboClient.Items(radcomboClient.SelectedIndex).Value

radcomboClient_Task.DataBind()

If radcomboClient.SelectedIndex >= 0 Then

If radcomboClient_Task.Items.Count > 0 Then

radcomboClient_Task.SelectedIndex = 0

End If

End If

' set focus to the dlient task control

radgridTimesheets.ClientSettings.ClientEvents.OnColumnCreated =

"setTimeout(function(){document.getElementById('" + radcomboClient_Task.ClientID + "').focus();},200);"

End Sub

0
Sebastian
Telerik team
answered on 31 Mar 2008, 08:35 AM
Hello Richard,

The client events of RadGrid accept only the name of the javascript handler, hence you cannot define the entire method in the way you specified.

If you want to focus the combobox after an item is selected in it, consider intercepting the ItemCreated event and execute the logic as shown here or use the ResponseScript collection of RadAjaxManager/RadAjaxPanel (in case you ajaxified the grid) to evaluate the script which sets the focus.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Richard
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or