I want to set the height of asp:panel to auto and I also want to ensure that max height is 400px and after that scroll bars must be present. I want to set it auto so that if the content is less than height 400px there will not be any empty space in the bottom. Any ideas?? :-)
Asked
Active
Viewed 1.4k times
2 Answers
9
I think the CSS max-height
attribute should be most appropriate to what you want:
<style type="text/css">
.myPanelClass { max-height: 400px; overflow: auto; }
</style>
<!--[if IE 6]>
<style type="text/css">
.myPanelClass { height: expression( this.scrollHeight > 399 ? "400px" : "auto" ); }
</style>
<![endif]-->
<asp:Panel runat="server" CssClass="myPanelClass">
....
</asp:Panel>
(EDIT: added IE6 "support")

Heinzi
- 167,459
- 57
- 363
- 519
-
Hi I tried your sugesstion but still panel height grows with the content – user294636 Apr 06 '10 at 07:41
-
I am working with IE6 is there any way to set max-height in IE6? – user294636 Apr 06 '10 at 07:57
-
@gowri: I've added something that should work with IE6 (according to various Internet sources), but I cannot test it since I don't have IE6 around here anymore... – Heinzi Apr 06 '10 at 08:12
0
Though I prefer Heinzi's answer in general, if you really must use IE6, perhaps just forcing the height to 400px in CSS? Haven't tried it, but it might work.
Another strategy might be to use Javascript, but you're then relying on it being present.
Whoever is forcing you to use IE6, it would also be nice for them to get with the program...

Martin Milan
- 6,346
- 2
- 32
- 44