Hi,
I have a radgrid with edit mode = custom edit form in asp.net page. There are several asp textbox in the FormTemplate.
I follow the sample in http://www.telerik.com/help/aspnet-ajax/grid-set-focus-on-textboxes-in-edit-control.html to set one of the textbox focus when itemcreated. However, I found that this the script did not work when I set AllowKeyboardNavigation = true in client setting. If I set AllowKeyboardNavigation = false, the textbox can get the foucs when I edit the row.
Below is my coding for the FormTemplate and ClientSetting
<
EditFormSettings
EditFormType
=
"Template"
>
<
EditColumn
UniqueName
=
"EditColumn"
AutoPostBackOnFilter
=
"true"
></
EditColumn
>
<
FormTemplate
>
<
asp:Table
ID
=
"EditTable"
runat
=
"server"
cellspacing
=
"0"
cellpadding
=
"0"
BorderStyle
=
None
>
<
asp:TableRow
>
<
asp:TableCell
>
<
asp:Label
ID
=
"lblOrgCode"
runat
=
"server"
Text
=
"Org. Code"
></
asp:Label
>
</
asp:TableCell
>
<
asp:TableCell
>
<
asp:TextBox
ID
=
"txtOrgCode"
Text='<%# Bind("OrgCode") %>' runat="server" CssClass="uppercase" TabIndex="1" Readonly='<%#IIf(TypeOf(Container) is GridEditFormInsertItem,"false","true")%>' ></
asp:TextBox
>
</
asp:TableCell
>
<
asp:TableCell
></
asp:TableCell
>
<
asp:TableCell
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator1"
Runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"txtOrgCode"
ForeColor
=
"Red"
ErrorMessage
=
"Organization code can not be empty!"
>
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator1"
runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"txtOrgCode"
ForeColor
=
"Red"
OnServerValidate
=
"OrgCode_ServerValidate"
ErrorMessage
=
"Org. code must be less than 100 characters"
>
</
asp:CustomValidator
>
</
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
>
<
asp:Label
ID
=
"lblOrgName"
runat
=
"server"
Text
=
"Org. Name"
></
asp:Label
>
</
asp:TableCell
>
<
asp:TableCell
>
<
asp:TextBox
ID
=
"txtOrgName"
Text='<%# Bind("OrgName") %>' runat="server" TabIndex="2" ></
asp:TextBox
>
</
asp:TableCell
>
<
asp:TableCell
></
asp:TableCell
>
<
asp:TableCell
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator2"
Runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"txtOrgName"
ForeColor
=
"Red"
ErrorMessage
=
"Organization name can not be empty!"
>
</
asp:RequiredFieldValidator
>
<
asp:CustomValidator
ID
=
"CustomValidator2"
runat
=
"server"
Display
=
"Dynamic"
ControlToValidate
=
"txtOrgName"
ForeColor
=
"Red"
OnServerValidate
=
"OrgName_ServerValidate"
ErrorMessage
=
"Org. name must be less than 100 characters"
>
</
asp:CustomValidator
>
</
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
>
Creation Date
</
asp:TableCell
>
<
asp:TableCell
>
<
asp:TextBox
ID
=
"txtCreationDate"
Text='<%# Bind("CreationDate") %>' runat="server" ReadOnly="true">
</
asp:TextBox
>
</
asp:TableCell
>
<
asp:TableCell
>
By
</
asp:TableCell
>
<
asp:TableCell
>
<
asp:TextBox
ID
=
"txtCreationUser"
runat
=
"server"
Text='<%# Bind("CreationUser") %>' ReadOnly="true">
</
asp:TextBox
>
</
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
>
Last Change Date
</
asp:TableCell
>
<
asp:TableCell
>
<
asp:TextBox
ID
=
"txtLastChangeDate"
Text='<%# Bind("LastChangeDate") %>' runat="server" ReadOnly="true">
</
asp:TextBox
>
</
asp:TableCell
>
<
asp:TableCell
>
By
</
asp:TableCell
>
<
asp:TableCell
>
<
asp:TextBox
ID
=
"txtLastChangeUser"
runat
=
"server"
Text='<%# Bind("LastChangeUser") %>' ReadOnly="true">
</
asp:TextBox
>
</
asp:TableCell
>
</
asp:TableRow
>
</
asp:Table
>
<
asp:Table
runat
=
"server"
>
<
asp:TableRow
>
<
asp:TableCell
HorizontalAlign
=
Left
>
<
asp:Button
ID
=
"Button1"
Text='<%#IIf(TypeOf(Container) is GridEditFormInsertItem,"Insert","Update")%>' runat="server" CommandName='<%#IIf(TypeOf(Container) is GridEditFormInsertItem,"PerformInsert","Update")%>' TabIndex="3"> </
asp:Button
>
<
asp:Button
ID
=
"Button2"
Text
=
"Cancel"
runat
=
"server"
CausesValidation
=
"False"
CommandName
=
"Cancel"
TabIndex
=
"4"
></
asp:Button
>
</
asp:TableCell
>
</
asp:TableRow
>
</
asp:Table
>
</
FormTemplate
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
ReorderColumnsOnClient
=
"True"
AllowColumnsReorder
=
"True"
AllowKeyboardNavigation
=
"true"
>
<
Selecting
AllowRowSelect
=
"True"
></
Selecting
>
<
KeyboardNavigationSettings
AllowSubmitOnEnter
=
"true"
EnableKeyboardShortcuts
=
"true"
AllowActiveRowCycle
=
"true"
CollapseDetailTableKey
=
"LeftArrow"
ExpandDetailTableKey
=
"RightArrow"
/>
</
ClientSettings
>
Below is my coding in setting the textbox focus on ItemCreated event.
If e.Item.IsInEditMode Then
If TypeOf (e.Item) Is GridEditFormInsertItem Then
ControlToFocus = DirectCast(DirectCast(e.Item, GridEditableItem).FindControl("txtOrgCode"), TextBox)
Else
' Dim lGridEditableItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
ControlToFocus = DirectCast(DirectCast(e.Item, GridEditableItem).FindControl("txtOrgName"), TextBox)
End If
End If
If Not ControlToFocus Is Nothing Then
Dim script As String = [String].Format("$get('{0}').focus(); $get('{0}').select();", ControlToFocus.ClientID)
RadScriptManager.RegisterStartupScript(Page, GetType(Page), "EditFocusScript", script, True)
End If
Thanks!