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

Grid edit template Focus() throwing Exception

8 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 10 Aug 2015, 09:28 PM
 I am trying to set focus to a textbox within the edit template and when it runs I get the following error:

A first chance exception of type 'System.NullReferenceException' occurred in NgeDataEntry.dll

 {"Object reference not set to an instance of an object."}

 

Not sure what I have wrong here. Can anyone spot the mistake.

 
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
           {
               UserControl myUserControl = e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl;
               string script = String.Format("$get('{0}').focus(); $get('{0}').select();", myUserControl.FindControl("RadTextBox2").ClientID);
               ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);
           }
       }

8 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Aug 2015, 05:16 PM

Hello,

 if your code is not worked than also try with the below code snippet. 

GridEditableItem editedItem = e.Item as GridEditableItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

 

Also try to access same control into ItemDataBound event.

Let me know if any concern.

Thanks,

Jayesh Goyani

0
Eyup
Telerik team
answered on 13 Aug 2015, 10:51 AM
Hello Guys,

I want to share that you can also achieve this requirement directly on the client instead of calling the RegisterStartupScript method:
<ClientSettings>
    <ClientEvents OnRowCreated="rowCreated" />
</ClientSettings>
JavaScript:
function rowCreated(sender, args) {
    var item = args.get_item()
    if (item.get_isInEditMode()) {
        var textBox = $telerik.findControl(item.get_editFormItem(), "RadTextBox2");
        textBox.focus();
    }
}

Hope this helps. Please give it a try and let me know about the result.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Luke
Top achievements
Rank 1
answered on 13 Aug 2015, 04:11 PM
I have tried what you posted with no success. 
0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Aug 2015, 04:14 PM

Hello Luke,

 It would be nice if you will provide full code or all require code for this.

Thanks,

Jayesh Goyani

0
Luke
Top achievements
Rank 1
answered on 13 Aug 2015, 04:17 PM

do you have an email I can send it too?

 

0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Aug 2015, 05:00 PM

Hello,

You can upload your project by using support ticket or upload your project any other site and share its link here.

jayeshgoyani@gmail.com

Thanks,

Jayesh Goyani

0
Luke
Top achievements
Rank 1
answered on 13 Aug 2015, 05:39 PM
ok ticket id is : 961711 
0
Eyup
Telerik team
answered on 18 Aug 2015, 09:20 AM
Hi Luke,

I've already replied in the mentioned support ticket thread.
If you have difficulties implementing the suggested approach, I can prepare a sample runnable web site for your convenience and send it to you.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Luke
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Eyup
Telerik team
Luke
Top achievements
Rank 1
Share this question
or