Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi...
I am using master page(Master3.master) in my application. I have applied javascript to find master page <div> width. I get div width successfully in javascript variable using following code at master head tag :

 <script type="text/javascript">
        function getwidth()
    {
        var content_div = document.getElementById('content');
        var content_width = content_div.clientWidth;
        alert('content_width=' + content_width + 'px');
        }
    </script>

but now i want to show this div width(content_width )at content page named "ContactUs_Design.aspx" that access above MasterPage.

My content page and master page are in different different folder and i am adding master page dynamically to content page.
I want to use variable 'content_width' at "ContactUs_Design.aspx" to show.
How can i find this....????

Thanks
Sunil Sharma
Posted
Updated 29-Mar-13 1:43am
v9

Hello,
If you are using JavaScript, and Want to access is on Content Page of Masterpage, then simply put the javascript code in the , head tag section of masterpage. By this , when you will, add any content page, linked with that master page, you will see java script working on that contantpage.
 
Share this answer
 
v2
Comments
sonusharma65 22-Mar-13 8:08am    
I have already written javascript in head tag of master page and it's working fine but the main issue is that my master page and content page resides in different different folder. I am adding dynamically master page for that content page. Now i want to use the value of javascript variable at content page. please clear with example...
thanks
Ankit_Sharma1987 22-Mar-13 8:51am    
have u tried to add this javascript in the head contentplaceholder of ur content page??
sonusharma65 22-Mar-13 8:56am    
yes, i have written javascript code at master page like this :

<script type="text/javascript">
function getwidth()
{
var content_div = document.getElementById('content');
var content_width = content_div.clientWidth;
alert('content_width=' + content_width + 'px');
}
</script>

It's working fine but now i want to use 'content_width' value at content page
Ankit_Sharma1987 22-Mar-13 9:01am    
when we make content page we have a contentplaceholder for the head section in every content page if u'll write this script in the contentplaceholder which has contentplaceholderID="head" it will work for that content page only
sonusharma65 23-Mar-13 0:41am    
I know this very well but i think you are not understanding what i really want. Please read my question carefully and reply me please. It's urgent for me....

Thanks
This is how I included div on Master page(outside ContentPlaceHolder):
XML
<div id="DivTest" style="width: 200px;">
</div>


This is the code I wrote on child page(inside ContentPlaceHolder):
JavaScript
<script language="javascript" type="text/javascript">
        //        function getwidth() {
        var content_div = document.getElementById('DivTest');
        var content_width = content_div.clientWidth;
        alert('content_width=' + content_width + 'px');
        // }
</script>


It worked.
 
Share this answer
 

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