Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
XML
I have a main page in which I have an iframe. Inside this iframe i am adding a child page.

Sample code as below.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            alert('hi from main');
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <iframe id="iframe1" runat="server" src="Child.aspx"></iframe>
        </div>
    </form>
</body>
</html>

Please note that I have added Jquery reference here.

Now my child page has code as below:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        $(document).ready(function () {
            alert('hi from child');
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

My questions are

why alert in main is getting displayed while in child page it says $ is undefined.
How can I pass JQuery source reference to child page without adding below line in child page

<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
Posted

1 solution

Hai

If u use jquery u need to include this line other wise jquery not work properly and also show undefined error.
HTML
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script></script>


The above line work as plugin or namespace for jquery embbed with ur project.

If u not Add Ajax reference in ur website,how u use Ajax tools ???

Try this link

jQuery introduction and how to use jQuery with ASP.NET Master page and simple pages[^]
 
Share this answer
 
v2
Comments
Pratik Gaikwad 14-Mar-14 0:41am    
@Aravindba... did you see the code? in my main.aspx it is added... I want that reference to be passed to the child.aspx if both are from same project
Aravindba 14-Mar-14 1:07am    
yeah i saw,u need to include that line in each and every html page otherwise jquery not work,
And what reference u passed to child page ? what u did here ,if main page open it show msg "hi form main" and in main page form u add a iframe and call child page ,if child page open it show msg "hi form child"

So if main page open show msg and in main page iframe call child page and if child page open it show msg.like this

here where u pass reference ? what type of reference ?
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script></script> this behave like as plugin or namespace in each page(separately),u cant reference this line form one page to other page.this is not dll ,can add dll and refer in all pages.
Note u cant reference that line from one page to another page this is client side,so one page open client side execute first then server side.

Otherwise u do like this,remove jquery function "$(document).ready(function ())" from child page ,and add one shoe message in child page load event like "Hi from child"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900