none
Microsoft JScript runtime error: Object expected

    Question

  • Hi,

    When I am calling my javascript function from server-side I get the error: "Microsoft JScript runtime error: Object expected"

    1) Below is my server side code through which I call the javascript function:

     protected void enabledstate(string s)

            {

                String sScript = "<script language=JavaScript>";

                sScript += "isCheck('" + s + "');";

                sScript += "</script>";

                ClientScript.RegisterStartupScript(GetType(), "RefreshPage", sScript);

            }

     

    2) Below is my javascript function:

    function isCheck(me) {

        var flag = 0;

        var checkBoxValue;

     

    var oHidStaticCheckCounter = $("#hidStaticCheckCounter")[0];

    var meID = (me.id == undefined) ? me : me.id;

    if (document.getElementById(meID).checked == true) {

          SelectedDocArray.setItem(me.id, me.value);

          eval(oHidStaticCheckCounter.value++);

        }

        else {

          SelectedDocArray.removeItem(me.id);

          eval(oHidStaticCheckCounter.value--);

        }

        if (parseInt(oHidStaticCheckCounter.value) == parseInt($("#hidTotalCount")[0].value)) {

          $("#groupModelsGrid_HeaderButton")[0].checked = true;

        }

        if (parseInt(oHidStaticCheckCounter.value) > 0 && GLOBAL_VAR_TOCHECK_ENABLED == true) {

          enabledlinks();

        } else if (parseInt(oHidStaticCheckCounter.value) == 0) {

          disabledlinks();

        }

        if (SelectedDocArray.length > 0 && GLOBAL_VAR_TOCHECK_ENABLED == true) {

          enabledlinks(true);

        } else if (SelectedDocArray.length == 0) {

          disabledlinks();

        }

        if (SelectedDocArray.length == 1) {

          try {

            enableEditLink();

          } catch (e) { }

        }

        else if (SelectedDocArray.length > 1 && GLOBAL_VAR_TOCHECK_DISABLE == false) {

          try {

            disableEditLink();

          } catch (e) { }

        }

     

        var iCounter = 0;

        var iPositionflag = 0;

        var iLastCounter = 0;

     

        for (var i = 2; i <= 17; i++) {

          var chk = "";

          if (i > 9) {

            chk = "groupModelsGrid_ctl" + i + "_CheckBoxButton";

          }

          else {

            chk = "groupModelsGrid_ctl0" + i + "_CheckBoxButton";

          }

          var chk1 = document.getElementById(chk);

          if (chk1) {

            if (chk1.type == "checkbox" && chk1.checked == true) {

              flag = 1;

              iPositionflag = i;

              iCounter = iCounter + 1;

              checkBoxValue = chk1.value;

            }

            iLastCounter++;

          }

        }

        if (flag == 1) {

          if (iCounter < 2) {

            enableEditLink();

            if (iPositionflag == 2) {

              enableddownbtn();

            }

            else if (iPositionflag == iLastCounter + 1) {

              enabledupbtn();

            }

            else {

              enableddownbtn(); enabledupbtn();

            }

          }

          else {

            disableddownbtn(); disabledupbtn();

          }

        }

        else {

          disableEditLink();

          disableddownbtn(); disabledupbtn();

        }

      }

     

    THANKS IN ADVANCE!!!

    Thursday, January 13, 2011 6:33 AM

Answers

  • "Microsoft JScript runtime error: Object expected"

    Debug from Visual Studio

    Place a breakpoint here ClientScript.RegisterStartupScript(GetType(), "RefreshPage", sScript);

    and step through... the error message in in Visual Studio's JIT

    this looks all wrong...

     protected void enabledstate(string s)

            {

                String sScript = "<script language=JavaScript>";

                sScript += "isCheck('" + s + "');";

                sScript += "</script>";

                ClientScript.RegisterStartupScript(GetType(), "RefreshPage", sScript);

            }

    There is no RefreshPage event handler in (x)html. The "language" attribute for script blocks is depreciated. A type attribute for <script> blocks is required.

    I have never used RegisterStartupScript, so I could be shooting my mouth off, but to me your syntax looks all wrong.

    You can get Client scripting errors (javascript... your error is in jscript... its occuring at the server) of type Object Expected when you use document.getElementById in the body onload event handler before the body tag has been closed by the IE8 parser.

    You may do better in a asp.net forum if someone else does not offer a better answer here... this forum is mostly about client markup, css and scripting


    Rob^_^
    Thursday, January 13, 2011 1:46 PM