2011-12-11 58 views
1

我需要動態更改此元素的寬度。所以我想從aspx.cs文件中添加一個width =「」屬性。我怎樣才能做到這一點?如何從aspx.cs中添加HTML屬性

<MyControl:Graph id="Graph1" runat="server" Height="510px"></MyControl:Graph> 
+0

博特確保你的問題是什麼? –

回答

1

Graph1.Width = 500;可能就足夠了。

0
Graph1.Properties["width"]="500px"; 
+0

它說「MyControl:Graph不包含屬性的定義..」 – Hzyf

1

如果您的控件繼承自WebControl,它將會有一個名爲Attributes的屬性。 您可以輸入:

Graph1.Attributes["height"] = "510"

請記住,在HTML的widthheight屬性不包含單位信息,它只是一個簡單的整數。 如果你正在尋找一個CSS inplementation使用:

Graph1.Style["height"] = "510px"