tags:

views:

206

answers:

2

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?? :-)

+3  A: 

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
+1 Be aware that `max-height` is unsupported in IE6, though.
Jørn Schou-Rode
Hi I tried your sugesstion but still panel height grows with the content
Any other sugesstions?
I am working with IE6 is there any way to set max-height in IE6?
@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
I have tested that :-)Its working :-)Thanks :-)
A: 

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