Solved

Asp.Net - Get Height of HtmlGenericControl

Posted on 2011-02-12
5
1,398 Views
Last Modified: 2012-05-11
Hi,

Using ASP.Net, how do you get the height of a HtmlGenericControl?

Non-Functional Example:

Dim ContentPaneControl As HtmlGenericControl = CType(Master.FindControl("ContentPane"), HtmlGenericControl)

Dim MyDivHeight As String = ContentPaneControl.Attributes("height").ToString

Thank you,
Ben
0
Comment
Question by:Beircheart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:BurnieP
ID: 34879952
If you change Attributes for Style?

Dim MyDivHeight As String = ContentPaneControl.Style("height").ToString
0
 

Author Comment

by:Beircheart
ID: 34880443
No go I'm afraid

"Object reference not set to an instance of an object"
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34880465

I think you have a problem with getting your control.

Get the ContentPlaceHolder first

Dim mContentPlaceHolder As ContentPlaceHolder = CType(Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
(where "ContentPlaceHolder1" is the ID of your ContentPlaceHolder.

Then try :

Dim ContentPaneControl As HtmlGenericControl = CType(mContentPlaceHolder .FindControl("ContentPane"), HtmlGenericControl)

0
 

Accepted Solution

by:
Beircheart earned 0 total points
ID: 34896024
Hi Burnie,

Unfortunately that didn't work either

However, I have implemented a workaround using Javascript (See attached). This code is embedded on my Master Page

While I am satisfied with this workaround, I would prefer to avoid such a method due to the fact that this function is now being called on every page even though it is only needed on one of them

I will leave this question open until Thursday in case someone can provide a solution rather than a workaround

For the sake of clarity, I will summarise what I'm trying to do:

I have a div in my Master page (Lets call it MasterPageDIV). I have a conent page called MyContentPage.aspx. I would like to get the height of MasterPageDIV using .Net code in the MyContentPage.aspx Page_Load event.

All the best,
Ben
<script type="text/javascript">

        try {
            window.onresize = SetImagePosition
        }
        catch (e) {
            // Ignore Error
        }

        function SetImagePosition() {
            try {
                
                document.getElementById('CalendarStyle').style.marginTop = 0;
                
                if (document.getElementById('Background-Home')) {
                    document.getElementById('Background-Home').style.marginTop = 1;
                }

                var ContentPaneHeight = document.getElementById('ContentPane').offsetHeight;
                var LinksPaneHeight = document.getElementById('LinksPane').offsetHeight;

                if (LinksPaneHeight < ContentPaneHeight) {
                    document.getElementById('CalendarStyle').style.marginTop = ContentPaneHeight - LinksPaneHeight + 10;
                    if (document.getElementById('Background-Home')) {
                        document.getElementById('Background-Home').style.marginBottom = 1;
                    }
                }

                else if (LinksPaneHeight > ContentPaneHeight) {
                    if (document.getElementById('Background-Home')) {
                        document.getElementById('Background-Home').style.marginTop = LinksPaneHeight - ContentPaneHeight;
                    }
                }
            }
            catch (e) {
                // Ignore Error
            }
        }

    </script>
</head>
<body onload="SetImagePosition()">

Open in new window

0
 

Author Closing Comment

by:Beircheart
ID: 34986373
This workaround will have to do
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question