Link to home
Start Free TrialLog in
Avatar of OddiC
OddiC

asked on

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.
Avatar of OddiC
OddiC

ASKER

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

Avatar of OddiC

ASKER

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?
Avatar of OddiC

ASKER

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.


ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OddiC

ASKER

Excellent- thank you for your informitive explanation.