Retrieve a Panel's style attributes

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
 
C

Chris Jackson

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>
 
S

Shahar

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"]);
 
J

John Spiegel

Thanks, Chris and Shahar!

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

- John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top