error: Uncaught TypeError: Cannot read properties of null (reading 'ej2_instances') sidebar

Hello,

I am copying the example from the link below to my _Layout and I am having the error attached, I have tried multiple examples and I always have this error message.

Can you help?



https://ej2.syncfusion.com/aspnetcore/Sidebar/SidebarWithMenu#/bootstrap5


Attachment: Capturar2_9e49ebc1.zip

3 Replies 1 reply marked as answer

SS Sivakumar ShunmugaSundaram Syncfusion Team August 17, 2022 01:00 PM UTC

Hi Roberto,


Greetings from Syncfusion support.


We have validated the reported issue in the ASP.NET Core Sidebar component. We have prepared a simple sample of the ASP.NET Core Sidebar component, and the sample works fine without any console errors.


We would like to let you know that the reported issue occurs due to an incorrect component ID used in the document.getElementById method. To overcome the issue, we suggest you use the correct ID in the method. We have attached the prepared sample for your reference.


Refer to the below code snippet.

[_Layout.cshtml]

 

    <ejs-sidebar id="default-sidebar" closeOnDocumentClick="false">

...

    </ejs-sidebar>

 

    <script>

document.addEventListener('DOMContentLoaded', function () {

        //create instances for sidebar element

        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];

        // Toggle Button to close and open the sidebar

        document.getElementById('toggle').onclick = function () {

            defaultSidebar.toggle();

        }

        // Close the sidebar

        document.getElementById('close').onclick = function () {

            defaultSidebar.hide();

        }

    });

 

    </script>


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Core_Sidebar1340346850.zip


Please check the attached sample and get back to us if you need any further assistance.


Note: If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Sivakumar S



Marked as answer

RO Roberto August 22, 2022 08:58 PM UTC

Hi,


It´s worked.


thanks



IL Indhumathy Loganathan Syncfusion Team August 23, 2022 06:02 AM UTC

Hi Roberto,


We are glad that your reported query has been resolved. Please get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon