Grid edit template Focus() throwing Exception

9 posts, 0 answers
  1. Luke
    Luke avatar
    6 posts
    Member since:
    Jul 2015

    Posted 10 Aug 2015 Link to this post

     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);
               }
           }
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 12 Aug 2015 in reply to Luke Link to this post

    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

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 13 Aug 2015 Link to this post

    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
  5. Luke
    Luke avatar
    6 posts
    Member since:
    Jul 2015

    Posted 13 Aug 2015 in reply to Eyup Link to this post

    I have tried what you posted with no success. 
  6. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 13 Aug 2015 in reply to Luke Link to this post

    Hello Luke,

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

    Thanks,

    Jayesh Goyani

  7. Luke
    Luke avatar
    6 posts
    Member since:
    Jul 2015

    Posted 13 Aug 2015 in reply to Jayesh Goyani Link to this post

    do you have an email I can send it too?

     

  8. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 13 Aug 2015 in reply to Luke Link to this post

    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

  9. Luke
    Luke avatar
    6 posts
    Member since:
    Jul 2015

    Posted 13 Aug 2015 in reply to Jayesh Goyani Link to this post

    ok ticket id is : 961711 
  10. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 18 Aug 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017