Em1
Em1

Reputation: 1095

Calculate height of a HTML-Table generated by HtmlTextWriter (C#)

I generate a HTML-Page from C#. In the HTML-Page there are a lot of elements. All of them have a absolute position.

One of these elements is a table. This table represents a object that keeps a double[]. Every double value is a new cell in a new row.

I iterate over double[] and create my table:

for (int i = 0; i < dbl.Length; i++)
{
  htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
  htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);
  htmlTextWriter.Write(dbl[i]);
  htmlTextWriter.RenderEndTag(); // td
  htmlTextWriter.RenderEndTag(); // tr
}

If the table has so much elements, that it cross an element that is below this table, I have to be responsive to this issue.

This means, I need to know how many pixels this table is long.

Of course I do know how many cells I generate and I also know BorderSize, Padding, Margin, etc.

But there are two problems. First although I know FontSize, FontFamily, FontWeight, I do not know how to include these information into a mathematical calculation.

Second I think in every browser the actual size is also different. I created a dummy table and recognized, that in one screen height I already have one cell difference between Opera and Firefox.

So I think in C# I am only able to approximate the actual height?!

The next idea I have is to include a JavaScript into my HTML. I've no experience with JavaScript, but my approach would be to find my tables and read out size. Then iterate over all elements and find all overlappings.

My questions are:

Hint: Other script languages than JavaSript are not applicable for my solution. JavaScript I only use if really necessary.

Upvotes: 0

Views: 1041

Answers (2)

Giedrius
Giedrius

Reputation: 8540

I think javascript is the answer, not c#. http://api.jquery.com/height/

Upvotes: 1

user390703
user390703

Reputation: 1

You cannot calculate the height in C#. Please use javascript to do this.

Upvotes: -1

Related Questions