ASP.NET标签宽度无法呈现给浏览器 [英] ASP.NET Label width not rendering to browser

查看:97
本文介绍了ASP.NET标签宽度无法呈现给浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于用户首选项动态加载控件的Web应用程序。标签和文本框在运行时加载。当我的老板将它部署到一个新的网络服务器时,标签宽度没有呈现给浏览器,但它适用于我从Visual Studio 2010运行它。我们都使用IE10。 Web服务器是运行IIS7.5的Windows 2008 R2。以下是我创建控件的方法:

 cell = new HtmlTableCell(); 
Label label = new Label();
label.Text = props.LabelText;
label.Width = 150;
cell.Controls.Add(label);





当我在我的机器上查看源代码时,它看起来像这样:

< pre lang =text>< td>< span style =display:inline-block; width:120px;> Company:< / span>< / td>



服务器的源代码如下所示:

< td>< span style =display:inline-block;>公司:< / span>< / td> 



宽度被删除,有没有人遇到这个?

解决方案

这是正确的:在内联元素上,宽度无关紧要;这些元素只占用渲染它们所需的空间。

怎么办?这取决于您想要实现的布局。你可以修改显示类型,将这个元素包装在div等其他元素中或修改外部HTML的布局(是td?),使用边距和/或填充等。



-SA


这是IE10中的兼容模式,一旦我为该网站启用它就可以正常工作。


Hi, I am working on a web application that dynamically loads controls based on user preferences. The Labels and Textboxes are being loaded at run time. When my boss deployed it to a new webserver the label widths were not rendering to the browser but, it works fine for me running it from Visual Studio 2010. We are both using IE10. The web server is a Windows 2008 R2 running IIS7.5. Here is how I create the control:

cell = new HtmlTableCell();
               Label label = new Label();
               label.Text = props.LabelText;
               label.Width = 150;
               cell.Controls.Add(label);



When I view the source code on my machine it looks like this:

<td><span style="display:inline-block;width:120px;">Company:</span></td>


Source code from the server looks like this:

<td><span style="display:inline-block;">Company:</span></td>


Width is dropped, has anyone come across this before?

解决方案

That's correct: on inline elements, width is insignificant; such elements only occupy as much space as it it required to render them.
What to do? It depends on the layout you want to achieve. You can modify display type, wrap this element in some other element like div or modify layout of outer HTML (is it "td"?), work with margins and/or padding, etc.

—SA


It was the Compatibility Mode in IE10, once I turned it on for that site it worked fine.


这篇关于ASP.NET标签宽度无法呈现给浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆