You must Sign In to post a response.
  • Category: JavaScript

    Javascript run time error: object expected

    I am getting " Javascript run time error: object expected" when calling function in javascirpt file.
    I am getting error when calling SizeContainers() fuction. how to fix this?

    here is my code

    .aspx

    <script language="javascript" type="text/javascript">
    // window.onload = onloadGrid("DatagridZipCode");
    $(document).ready(function () {

    onloadGrid("DatagridZipCode");

    });


    .js file code
    ----------------

    function onloadGrid(sGridName) {
    //some code is there here

    MakeHeader();
    }
    function MakeHeader()
    {
    //some code is there here
    InitGridNoGroups();
    }
    function InitGridNoGroups()
    {
    SizeContainers();
    }
    function SizeContainers()
    {
    //some code here
    }
  • #764420
    This error replicated when You attempted to pass a non-JavaScript object to a built-in function that expects a JavaScript object
    There are multiple reason for this error ? some of the possible causes for this error are as below
    - You have used JQuery but not added its reference tags in HEAD section of ASPX
    - Some of the JQuery methods are not working properly on old browser version (IE8)
    - in your .JS file 'SizeContainers' method should exist
    can you share your code so that we can help you better in order to resolve issues

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764422
    Hai Chinnari,
    As you are calling the nested inner function of the JavaScript which is not available in the global scope and due to that you are getting the error message.
    If you still want to implement the same, you can modify your code like:

    function onloadGrid(sGridName) {
    //some code is there here
    MakeHeader();
    }
    var MakeHeader=function(){
    //some code is there here
    InitGridNoGroups();
    }
    var InitGridNoGroups=function(){
    {
    SizeContainers();
    }
    var SizeContainers=function(){
    //some code here
    }

    And then you can call it like:

    var onloadGrid= new onloadGrid("DatagridZipCode");
    onloadGrid.MakeHeader();

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764538
    Hi chinnari,
    1) Make sure you have given proper reference of your JS file inside aspx [Eg. <script src="JavaScript1.js"></script>].
    2) Make sure if any element/control present inside function SizeContainers() which belongs to aspx. Then its id must be equal to id what you have defined in the aspx, for this just "View Source" on a aspx and find your elements exact id.
    3) Make sure you don't have any variable defined with same name as "SizeContainers" in javascript as well as clientScript registered on .cs page.
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


  • Sign In to post your comments