variable is set to null after jquery appendTo

4 posts, 1 answers
  1. piotre6
    piotre6 avatar
    18 posts
    Member since:
    Apr 2011

    Posted 17 Jul 2012 Link to this post

    I have grid on my page located in div with id "Lists":

    <div id="Lists"
        <telerik:RadGrid runat="server" ID="mygrid"
        <ClientSettings> 
            <ClientEvents OnGridCreated="document_Grid_OnGridCreated" /> 
        </ClientSettings
        </telerik:RadGrid
    </div>
    <div id="ParentList">
    </div>

    when grid is created documentGrid variable is set with that grid:

    <script type="text/javascript" >
        var documentGrid = null;
        function document_Grid_OnGridCreated(sender, args) {
            documentGrid = sender;
        }
    </script>

    to this point everything seems to be fine, I can call following code:
    function updateDocumentGrid(){
        documentGrid.get_masterTableView().rebind();
    }

    after I move Lists div inside another div with id ParentList
    global variable window.documentGrid is null.

    is there any way to prevent variable documentGrid from beeing set to null?
  2. Kostadin
    Admin
    Kostadin avatar
    1709 posts

    Posted 20 Jul 2012 Link to this post

    Hello Piotr,

    I tried to reproduce your issue but to no avail. I attached a small sample where documentGrid variable is set with the grid. I place the RadGrid in div with id List and append it to another div with id ParentList as in your scenario. Could you please check it and let me know how it differs from your real setup? Also could you make the appropriate changes in my project, so I can test it locally?

    Kind regards,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. piotre6
    piotre6 avatar
    18 posts
    Member since:
    Apr 2011

    Posted 20 Jul 2012 Link to this post

    Hi Kostadin,
    thank you for sending me project. I've tried to reproduce my error using your code but I didnt manage.
    I've added many files from my project (controls, scripts, images etc.) and finally I got same error.
    Please run attached project and put breakpoint to file Scripts/Document.js at line 72.
    After line is passed - function appendTo is called documentGrid is set with null value.

    I hope you will get same result and will be able to help. I came with temporary solution which is commented line 73
    however I'd be glad to know what cases the problem and how to get rid of it.

    I couldn't upload project so I've uploaded it to sendspace:
    http://www.sendspace.pl/download/YTo0OntzOjc6ImRhdGVfaW4iO2k6MTM0MjgxOTMzNjtzOjU6InRpdGxlIjtzOjc6InRlbGVyaWsiO3M6OToiZmlsZV9uYW1lIjtzOjIzOiJ2YXJpYWJsZWlzc2V0dG9udWxsLnJhciI7czo1OiJ0b2tlbiI7czoyMzoiOGVjOGMyMjZkNzg0NTU2NWI5OWJmZmIiO30dfASDF34vasd3245bvs

    Thanks,
    Piotr
  5. Answer
    Kostadin
    Admin
    Kostadin avatar
    1709 posts

    Posted 25 Jul 2012 Link to this post

    Hello Piotr,

    The script that you have in DocumentsList.aspx file causes the problem. When you move a container inside another container the script is perform again and set the variable "documentGrid: to null, as in your case. You can simply fix that as you move the script outside the container.
    <script type="text/javascript" >
        var documentGrid = null;
        function document_Grid_OnGridCreated(sender, args) {
            documentGrid = 1;
        }
    </script>
    <div id="DocumentList" style="display:none; height:100%">


    All the best,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top