开发者

Getting A Control's Width ASP.NET

In asp.net, how do I get a control's height according to its percentage?

I can get the width property but I set it to 100% and I need the actual pixels

I need it so I can customize my website开发者_如何学编程 according to the computer's resulotion. (It can be any control - panel,div, etc)


Just access the (out of the box) control's height property in pixels. Calculate the ratio of this width divided by width of its container in the page and express this number as a percentage.

For example:

(myControl.height/myPanel.height)/100 + "%";

However, this is not the way to design a Web page to play nice in different sized browsers. Depending on what type of control you're using, this could get real messy and I'm just talking appearance here. Use fixed width for this and your container. Progressively enhance your site with CSS and JS if you need to.

At the risk of getting roasted, I'm going to say this: NEVER used liquid layouts - they change the ratio of the layout and destroy the page composition. Using liquid layouts always ends up with you having to apply code to change the image/height ratio of your images in relation to their container - and this always results in loss of image quality and/or bad page composition.


I believe this is not possible on server side because:

  • The output layout is modified until the rendering phase. Before that these estimations would be wrong/misleading and hence imho if they did exist, they would be bad design.
  • layout and the actual pixels depend on the browser settings and interpretation of HTML standard. Even though ASP.NET has some knowledge about differences of browsers it DOES NOT have direct info about browser neither contain all rendering engines.

The percentages are redirected to browsers rendering engine, I doubt standard ASP.NET controls do anything at all with the specific values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜