How can I debug this JS error? (I get the stupid nondescript: "Microsoft JScript runtime error: Object expected" ...exception alert).

Well basically,

I am re-using some code that another developer who no longer works on this project created, and, I do believe I copied over all necessary (external, in an 'Includes" folder of his and now my solution) .js files, all classes, references, etc. to make it compile and run ok. My problem is, he has this js function that runs on mouse-over of GridView records, and whenever I run the app, I get the nondescript "Object Expected" error... with no other details. VS2008 takes me to the temporary (run-time) javascript that it istrying to execute, but it gives no indication of WHAT object is expected but not there....! I assume the object is the function result, but I've looked at the function and the way in which it is being wired up (in the GridView's OnItemDataBound- a bit of html triggers the onclick for each record), and I can't figure uot why it isn't working....

This is really giving me a hard time. If anyone has any suggestion, I am greatly appreciative. It just doesn't make sense- I must be missing something from his project which I reused this code from.

Thanks much,

oddic


PS: Really, I just need to figure out a way to step into the acutal JS function and see it execute. Can someone show me how to do this is VS2008 (I tried setting breakpoints in the external .js file, but they were not hit (VS says this is because the file "is not loaded".... apparently not at design or runtime).

Any and all help is seriosuly awesome!!!!!!! Thanks again.
OddiCAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
For future reference the "undescriptive" "Object Expected" is typically triggered when you mistyped a function name or the function does not exist at all on the current page usually the result of a failed include due to incorrect path. In your case, it seems the problem was being triggered by:
nameControl.show(textField, name);  

The "Object Expected" seems to have been "nameControl". Basically, from the browser's point of view, you were trying to invoke a method from a non existing object.
0
 
OddiCAuthor Commented:
Here is the code if it helps anyone debug manually!!


//This is the main method that is returning no object (or maybe one of the params is null????) I dunno.

function showNameControl(textField, name) {
nameControl.show(textField, name);  
}





//This is the "show" function of nameControl object
this.show = show;
  function show(field, name) {
    //alert(name);
    // If the calendar is visible and associated with
    // this field do not do anything.
    if (nameField == field) {
      return;
    } else {
      nameField = field;
    }

    if(document.getElementById){
 
     nameH = document.getElementById(nameId);
      nameH.innerHTML = nameDrawTable(name);

      setElementProperty('display', 'block', 'NameControlIFrame');
      setProperty('display', 'block');

      var fieldPos = new positionInfoNameControl(nameField);
      var namePos = new positionInfoNameControl(nameId);

      var x = fieldPos.getElementLeft();
      var y = fieldPos.getElementTop();
      //alert('x:' + x + '; y:' + y);
      setProperty('left', x + "px");
      setProperty('top', y + "px");
      setElementProperty('left', x + "px", 'NameControlIFrame');
      setElementProperty('top', y + "px", 'NameControlIFrame');
      setElementProperty('width', namePos.getElementWidth() + "px", 'NameControlIFrame');
      setElementProperty('height', namePos.getElementHeight() + "px", 'NameControlIFrame');
    }
  }



//This is the dynamic runtime line where VS directs me upon the Exception occuring

<span onmouseover="showNameControl(this,'Moritz Sport & Marine');">Moritz Spo...</span></td><td>10/27/05</td><td>..., etc.
Here is the code if it helps anyone debug manually!!
 
 
//This is the main method that is returning no object (or maybe one of the params is null????) I dunno.
 
function showNameControl(textField, name) {
nameControl.show(textField, name);  
}
 
 
 
 
 
//This is the "show" function of nameControl object
this.show = show;
  function show(field, name) {
    //alert(name);
    // If the calendar is visible and associated with
    // this field do not do anything.
    if (nameField == field) {
      return;
    } else {
      nameField = field;
    }
 
    if(document.getElementById){
  
     nameH = document.getElementById(nameId);
      nameH.innerHTML = nameDrawTable(name);
 
      setElementProperty('display', 'block', 'NameControlIFrame');
      setProperty('display', 'block');
 
      var fieldPos = new positionInfoNameControl(nameField);
      var namePos = new positionInfoNameControl(nameId);
 
      var x = fieldPos.getElementLeft();
      var y = fieldPos.getElementTop();
	//alert('x:' + x + '; y:' + y);
      setProperty('left', x + "px");
      setProperty('top', y + "px");
      setElementProperty('left', x + "px", 'NameControlIFrame');
      setElementProperty('top', y + "px", 'NameControlIFrame');
      setElementProperty('width', namePos.getElementWidth() + "px", 'NameControlIFrame');
      setElementProperty('height', namePos.getElementHeight() + "px", 'NameControlIFrame');
    }
  }
 
 
 
//This is the dynamic runtime line where VS directs me upon the Exception occuring
 
<span onmouseover="showNameControl(this,'Moritz Sport & Marine');">Moritz Spo...</span></td><td>10/27/05</td><td>..., etc.

Open in new window

0
 
OddiCAuthor Commented:
NOTE: I just debugged his projefct (where this JS functioned worked) and the JS debugger worked fine and jumped right to the external JS file and the function in question! This leads me to believe that the 'object expected' may be the link to the JS file..... But I have it referenced clearly at the top of my master aspx page:

<script language="javascript" src="<%=Request.ApplicationPath %>/Includes/NameControl.js"></script>

Anyone know what gives?
0
 
OddiCAuthor Commented:
Gosh I'm a dufus!

Well, sorry to make anyone follow along as I figured this out myself, but... after posting my last comment, I focused on the script reference in the aspx page and... yep! His project had different directory structure so VS couldn't even find the JS function I was trying to execute on mouseover.

Simply put:

<script language="javascript" src="<%=Request.ApplicationPath %>/Includes/NameControl.js"></script>

----just needed to be-------

<script language="javascript" src="<%=Request.ApplicationPath %>Includes/NameControl.js"></script>

((no preceeding "/"))


That's all folks! Hopefully someone else will benefit from this mundane exception fix.


0
 
OddiCAuthor Commented:
Excellent- thank you for your informitive explanation.
0
All Courses

From novice to tech pro — start learning today.