Hi localhost,
Thank you for using Microsoft Newsgroup Service. Based on your description.
You want to enumerate a ASP.NET HtmlControl(runat=server)'s attributes in
server side code. If my understanding of your problem is correct, here is
my suggestion:
1. As for All the controls in System.Web.UI.HtmlControls namespace, each of
them has a Attributes member which contains all the attributes of the
HtmlControl. And the Attributes member has a two sub members, one is
"keys"(can loop through by for each), the other is "Item", you can get a
certain attribute of the HtmlControl via such code:
control.Attributes.Item("width")
it returns a string value
However, since the "Item" member of the HtmlControl's "Attributes" member
is not a Collection Class, you can't enumerate all the attributes in it
using "for each" directly on the "Item". But you can loop throuth them by
using the Keys member together. For example. Suppose there is a HtmlTable
on a aspx page:
<TABLE id="tbTest" cellSpacing="1" cellPadding="1" width="312" height="200"
border="1"
runat="server" style="WIDTH: 312px; HEIGHT: 128px">
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
then, in the page's code-behind file , you can loop throuth the table's
attributes as below:
For Each key As Object In tbTest.Attributes.Keys
Response.Write("<br>" + key.ToString() + ":" +
tbTest.Attributes.Item(key).ToString())
Next
2. As or you condition, you want to get the attributes in the child control
of a UserControl(ascx control). You need to first use Control or Page
class's Find Control method to find the certain control. And then, use the
above way in 1 to loop through all of its attributes
Please try out the preceding suggestions and let me know whether they help.
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)