【发布时间】:2013-04-01 22:04:42
【问题描述】:
我有一个 ASP.NET、C# Web 应用程序,它的 DIV 标记设置为 100%,因此 div 的内容可以根据内容扩展或缩短。这很好用,但我想修改它,以便如果内容低于某个宽度,则将宽度设置为标准宽度。因此,对于仅返回包含 2 列且数据不多的表的页面,这将消除看起来非常小的 DIV 标记。
我设置了 DIV 和表格的 ID 和 runat 属性,但是当我尝试通过单击页面上的按钮来获取宽度时,它总是返回 null:
<div id="content" runat="server">
<table class="MainContent" width="100%" id="MainTable" runat="server">
'data is in this table that could be 2 columns or 20, it's loaded
'dynamically in a gridview
</table>
</div>
我的按钮代码:
string s = content.Attributes["width"];
如何在我的网络应用程序中执行此操作?一、仅限使用ASP.NET 2.0和.NET 3.5框架。
【问题讨论】:
-
服务器不知道 div 的宽度。这是由客户决定的。
-
@JohnPick - 谢谢...我确实找到了基本 html 的解决方法:内表/div