views:

43

answers:

3

I am working on ASP.NET 3.5, c#, visual studio 2010. I have made a master file and a default page that uses this master file. I have placed a couple asp:contentplaceholders in the master and corresponding code in the page that uses this master. I have also inserted JavaScript like this in the content page (and not the master):

<asp:Content ID="Content6" ContentPlaceHolderID="Mainpage" Runat="Server">

<script src="path1" type="text/javascript"></script>  
<script src="path2" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        var options = {
            //some java code
        };

        $(".mycssclass").effect(options);
    });
</script>
</asp:Content>

On running the website I get the following runtime error in visual studio:

Microsoft JScript runtime error: 'this.node' is null or not an object

and it point to some function inside the JavaScript like

this.node.onload=function(){..............//I am not a java guy so do not know much about this  

Where am I going wrong? Why does the site compile correctly but throw this runtime error?

I also tried inserting this java code inside the master file in the <head>, but same error. This is urgent please so if someone experienced can pinpoint where exactly to put the code that would be solve my problem quickly.

+2  A: 

Have you included a reference to the jQuery library? A good practice would be to have the jQuery include in the Master.

<head>
   <script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;
   </script>
   <!-- the remainder of your .js references should follow-->
</head>

If it's your intention to have that script run on 'page load', then ensure you have it set correctly:

$(document).ready(function() {
    // put all your jQuery goodness in here.
});

More info on jQuery document ready.

p.campbell
You mean I should include the above line in my master file? header tag right?
VP
How do I check for references to jQuery lib? No dll that represent a jQuery lib seems to be present inside my bin folder in my project.
VP
No, you can include it in the page proper, not in the master file, if you so choose. But you should go ahead and link that one in the master file, it'll be much more handy later.
drachenstern
@VP ~ you don't need a jQuery dll. You need to link just like he gave you above.
drachenstern
@drachenstern: I recommended placing the jQuery script ref in the Master for simplicity's sake.
p.campbell
tried tht ...does not work.same error..so I now have the reference as above in my master file and the javascript code in the page that uses that master. But still does not work . Any suggestions/ideas?
VP
@p.campbell ~ I agree, for simplicity sake, but for learning sake, it is just as well to include it where you need it. However, he's having a bit of a problem with his compiler.
drachenstern
@VP ~ We all do it the way we are telling you. Have the script code above in this answer in your master page `<head>` block, have the code block on your page like you have it, except change the line I referenced in my comment or that @p.campbell referenced in his answer or the one given by @Josh to see the best effect. If you don't make both of those changes, it should fail every time. Additionally, you may need to turn off JScript checking on your VS instance, which, to be honest, I don't use on mine.
drachenstern
I do have 1 more question though. Right now the javascript works fine and produces the zooming effect that I wanted on the image in my web page. However right now it zooms whenever I hover the mouse over it. I want a slight modification in my asp.net/c# code. I want to activate the zooming effect on the press of a button. So I will put in a button that says "press here if u wanna zoom" and when this is pressed I want to do something (like activate the javascript) in my event handler code in c#. How can I achieve this? Any idea?
VP
A: 

I'm not sure exactly what it is you are doing with that snippet of code, but I don't think it is the proper syntax.

You probably should re-write it to look like this:

$(document).ready(
function () {
        var options = {
            //some java code
        };

        $(".mycssclass").effect(options);
});

Just passing in the function to the jQuery selector will probably get some wonkiness.

Josh
yeah Josh.. thats exactly how it the query looks...but still I have having that error
VP
@VP - appologies then... but your question indicates you left off the $(document).ready() call. You should update your question to correct this so others don't assume the problem lies there.
Josh
i am sorry about that..I updated it. thanks
VP
I do have 1 more question though. Right now the javascript works fine and produces the zooming effect that I wanted on the image in my web page. However right now it zooms whenever I hover the mouse over it. I want a slight modification in my asp.net/c# code. I want to activate the zooming effect on the press of a button. So I will put in a button that says "press here if u wanna zoom" and when this is pressed I want to do something (like activate the javascript) in my event handler code in c#. How can I achieve this? Any idea?
VP
A: 

Thank you everyone! there was no problem with either the syntax in the javascript or the location/page where it was first included by me. I just figured out that the mistake was somewhere else. This javascript works on an <img> tag. It zooms the image insdie the <img> tag. I was using the <asp:ImageButton> instead og <img>. It works perfect as soon as I replaced it. Thank you all for your time and the knowledge sharing.

VP