Retrieve a Panel's style attributes

  • Thread starter Thread starter John Spiegel
  • Start date Start date
J

John Spiegel

Hi all,

How can I read through the style attributes for a server control? It would
be so convenient if one could reference an index, something like:
pnlPageHeader.Style.Keys["Top"].ToString();

TIA,

John
 
Well, you can get an enumerator on Keys and iterate through. This sample is
from MSDN:

<html>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs e) {
Message.InnerHtml += "<h5>The Text Box's CssStyleCollection
contains:</h5>";

IEnumerator keys = MyText.Style.Keys.GetEnumerator();

while (keys.MoveNext()) {

String key = (String)keys.Current;
Message.InnerHtml += key + "=" + MyText.Style[key] + "<br>";
}
}
</script>
<body>
<span id="Message" MaintainState="false" runat="server" />
<p>
<b>Enter some text:</b> <br>
<input id="MyText" type="text" value="Type a value here."
style="font: 14pt verdana;width:300;" runat="server"/>

</body>
</html>
 
John Spiegel said:
Hi all,

How can I read through the style attributes for a server control? It would
be so convenient if one could reference an index, something like:
pnlPageHeader.Style.Keys["Top"].ToString();

TIA,

John

pnlPageHeader.Style["Top"] = "5";
Response.Write(pnlPageHeader.Style["Top"]);
 
Thanks, Chris and Shahar!

Once I remembered case-sensitivity, the ["TOP"] indexing worked quite well!

- John
 
Back
Top