Click here to Skip to main content
16,004,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

I have a javascript function which adjusts the column height(div) at runtime.

An exception is thrown saying object required.

Following is my function...
function AdjustColumnsHeight() {
    // get a reference to the two DIVS that make up the columns
    var centerCol = window.document.getElementById('centercol');
    var leftCol = window.document.getElementById('leftcol');
    // calculate the max height

    var hCenterCol = centerCol.offsetHeight;
    var hLeftCol = leftCol.offsetHeight;
    var maxHeight = Math.max(hCenterCol, hLeftCol);

    // set the height of all 2 DIVS to the max height
    centerCol.style.height = maxHeight  + 'px';
    leftCol.style.height = maxHeight  + 'px';
      }


And Following is my Master Page..

<div id="container">

        <div id="leftcol">
            <leftMenu:Leftmenue ID="leftMenu1"  runat="server" />
        </div>

        <div id="container2">
            <div id="centercol">
<asp:ContentPlaceHolder id="MainContent"  runat="server">      /asp:ContentPlaceHolder>
            </div>
        </div>
</div>



If I put the centercol div first,then leftcol cannot be found and
If I put the leftcol div first,then centercolcannot be found


Please help me I am in puzzled
Posted
Updated 20-Jun-11 21:04pm
v4
Comments
Anupama Roy 21-Jun-11 3:41am    
are you calling this javascript function from content page or from master page itself?
[no name] 21-Jun-11 3:43am    
I tried Both
Anupama Roy 21-Jun-11 3:45am    
I ran from master page's page load like this for testing this.Menu1.Attributes.Add("onclick", " return AdjustColumnsHeight();"); it doesnt throw any exception..both div's i could find..how are you invoking the function?
[no name] 21-Jun-11 3:50am    
please try this within script bloc:
window.onload = function() { AdjustColumnsHeight(); }

I tried to call from window.onload as you said.Works fine if div is inside form

C#
<form id="form1" runat="server"> </form>


Looks like you have placed div wrongly which might be causing the issue.Place in form tag & test again.
 
Share this answer
 
use FireBug for FF and IEWebDeveloper tool for IE to find control ID. because if the control in content placeholder asp.net put some prefix to control id like ctl00_. I suggest if you do not know the control id better to find control id using some tools I mentioned above.
 
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