I have a Master Page set up and I am pretty new to the way it behaves. However, I have various things that I typically resize with ease using a javascript I wrote a while back.
I found this page for executing javiscript on a content page. I am not sure if it is the best way to do it or not, but it seems to execute the javascript. However, now the javascript fails because I guess from the content page it cannot see the various
things I am trying to resize?
Simply put, I am just looking for the best way to resize an object on a content page using javascript.
The error says: "Microsoft JScript runtime error: Object required"
You can apply javascript anywhere on any page as long as it contains the <script> tags.
I recommend you download jQuery and then you can simply apply the following:
<script type="text/javascript" src="jquery-1.7.1.js" /> // whichever version of jQuery you download
<script>
$(document).ready(function() {
// Use if your object is not an asp control
$("#yourobjectid").height(200); // put value you need
$("#yourobjectid").width(200); // put value you need
// use if your object is an asp control
$(document.getElementById('<%=aspControlName.ClientID%>').height(200); // put value you need
$(document.getElementById('<%=aspControlName.ClientID%>').width(200); // put value you need
});
</script>
This is great and all, but doesn't help me. My javascript functions 100% as it should when on a page by itself, but for some reason it wo't work with elements on my content page. Is there any way to execute the javascript from the content page and have it
work with the elements on the page? The object references are coming up null, with that being said and the fact that I am referencing them using the same method as you showed above, your way would result in the same issue.
You will need to post your markup. It won't matter where the javascript is as when the page has rendered it's all on the one page anyway. Post your code and I'm sure we can debug it to find the issue.
Quick note: are the objects server controls i.e. <asp:Textbox etc? If so you need to refer to them like:
Ah is it possible that the javascript you are using is held in a seperate js file and not on the page itself? If so then you need to obtain the controls clientid first (before you reference the js file in your html):
// eg
var aspcontrol = "<%=txtControlName.ClientID%>";
And then use the above var instead of the control name in the seperate js file:
// i.e. change:
$(document.getElementById('<%=txtControlName.ClientID%>')).width(100);
// to
$(aspcontrol).width(100);
mkruluts
Member
62 Points
22 Posts
Resize objects on the content page with javascript
Jun 15, 2012 04:44 PM|LINK
I have a Master Page set up and I am pretty new to the way it behaves. However, I have various things that I typically resize with ease using a javascript I wrote a while back. I found this page for executing javiscript on a content page. I am not sure if it is the best way to do it or not, but it seems to execute the javascript. However, now the javascript fails because I guess from the content page it cannot see the various things I am trying to resize?
Simply put, I am just looking for the best way to resize an object on a content page using javascript.
The error says: "Microsoft JScript runtime error: Object required"
breath2k
Contributor
2101 Points
821 Posts
Re: Resize objects on the content page with javascript
Jun 16, 2012 12:44 PM|LINK
You can apply javascript anywhere on any page as long as it contains the <script> tags.
I recommend you download jQuery and then you can simply apply the following:
<script type="text/javascript" src="jquery-1.7.1.js" /> // whichever version of jQuery you download <script> $(document).ready(function() { // Use if your object is not an asp control $("#yourobjectid").height(200); // put value you need $("#yourobjectid").width(200); // put value you need // use if your object is an asp control $(document.getElementById('<%=aspControlName.ClientID%>').height(200); // put value you need $(document.getElementById('<%=aspControlName.ClientID%>').width(200); // put value you need }); </script>mkruluts
Member
62 Points
22 Posts
Re: Resize objects on the content page with javascript
Jun 16, 2012 06:42 PM|LINK
This is great and all, but doesn't help me. My javascript functions 100% as it should when on a page by itself, but for some reason it wo't work with elements on my content page. Is there any way to execute the javascript from the content page and have it work with the elements on the page? The object references are coming up null, with that being said and the fact that I am referencing them using the same method as you showed above, your way would result in the same issue.
breath2k
Contributor
2101 Points
821 Posts
Re: Resize objects on the content page with javascript
Jun 16, 2012 07:23 PM|LINK
You will need to post your markup. It won't matter where the javascript is as when the page has rendered it's all on the one page anyway. Post your code and I'm sure we can debug it to find the issue.
Quick note: are the objects server controls i.e. <asp:Textbox etc? If so you need to refer to them like:
document.getElementById('<%=aspControlName.ClientID%>')instead of:breath2k
Contributor
2101 Points
821 Posts
Re: Resize objects on the content page with javascript
Jun 16, 2012 07:29 PM|LINK
Ah is it possible that the javascript you are using is held in a seperate js file and not on the page itself? If so then you need to obtain the controls clientid first (before you reference the js file in your html):
And then use the above var instead of the control name in the seperate js file:
// i.e. change: $(document.getElementById('<%=txtControlName.ClientID%>')).width(100); // to $(aspcontrol).width(100);