473,569 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enumerate Control Attributes?

What is the best and/or fastest way to enumerate
attributes of an HTML control?

In my page template, I have:

<body id="myBody" bottomMargin="0 " leftMargin="0"
topMargin="0" rightMargin="0" MS_POSITIONING= "GridLayout "
class="Body" runat="server">

And in my code-behind I want to look for the leftMargin
attribute and change its property to "5" and remove the
class attribute.

Thanks.
Nov 18 '05 #1
7 4541
Because you can directly access the individual attributes
by name. I don't know why you want to enumerate through
the attributes.
myBody.Attribut es("leftMargin" ) = 5
myBody.Attribut es("class") = ""
Bin Song, MCP
-----Original Message-----
What is the best and/or fastest way to enumerate
attributes of an HTML control?

In my page template, I have:

<body id="myBody" bottomMargin="0 " leftMargin="0"
topMargin="0 " rightMargin="0" MS_POSITIONING= "GridLayout "
class="Body" runat="server">

And in my code-behind I want to look for the leftMargin
attribute and change its property to "5" and remove the
class attribute.

Thanks.
.

Nov 18 '05 #2
Hi localhost,

Thank you for using Microsoft Newsgroup Service. Based on your description.
You want to enumerate a ASP.NET HtmlControl(run at=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.H tmlControls 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.Attribu tes.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.Attribut es.Keys
Response.Write( "<br>" + key.ToString() + ":" +
tbTest.Attribut es.Item(key).To String())
Next
2. As or you condition, you want to get the attributes in the child control
of a UserControl(asc x 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.)

Nov 18 '05 #3
I have used this, maybe it will work for you:

IEnumerator keyEnum = controlName.Att ributes.Keys.Ge tEnumerator();
while ( keyEnum.MoveNex t() )
{
string currentKey = (string)keyEnum .Current;
string currentVal = controlName.Att ributes[currentKey];
}

"localhost" <pr*******@coho rt.ces> wrote in message news:<02******* *************** ******@phx.gbl> ...
What is the best and/or fastest way to enumerate
attributes of an HTML control?

Nov 18 '05 #4

I need to enumerate all of the attributes, and if I find
the one I want, then I need to edit its value. If I
don't find the one I want, then I need to add it with a
default value. I can't access the individual attributes
by name if I don't know what is in there in the first
place.

-----Original Message-----
Because you can directly access the individual attributesby name. I don't know why you want to enumerate through
the attributes.
myBody.Attribu tes("leftMargin ") = 5
myBody.Attribu tes("class") = ""
Bin Song, MCP
-----Original Message-----
What is the best and/or fastest way to enumerate
attributes of an HTML control?

In my page template, I have:

<body id="myBody" bottomMargin="0 " leftMargin="0"
topMargin=" 0" rightMargin="0" MS_POSITIONING= "GridLayout "class="Body " runat="server">

And in my code-behind I want to look for the leftMargin
attribute and change its property to "5" and remove the
class attribute.

Thanks.
.

.

Nov 18 '05 #5
Hi localhost,

Thank you for using Microsoft Newsgroup Service. Based on your description.
You want to enumerate a ASP.NET HtmlControl(run at=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.H tmlControls 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.Attribu tes.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.Attribut es.Keys
Response.Write( "<br>" + key.ToString() + ":" +
tbTest.Attribut es.Item(key).To String())
Next
2. As or you condition, you want to get the attributes in the child control
of a UserControl(asc x 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.)
Nov 18 '05 #6
Hi Localhost,

Is my suggestion helpful to you? Have you resolved your problem? Please let
me know if you have any thing unclear on it.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7
Thanks for working on this. FindControl did not work for
me because I had multiple elements nested within each
other. I did not want to use a foreach loop because of
the slowness. I used IEnumerator on the Keys collection
and that worked fine.

Thanks anyway.

-----Original Message-----
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 inserver side code. If my understanding of your problem is correct, here ismy suggestion:


Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4557
by: MuZZy | last post by:
Hi, I need to build a function which would return all controls which are upper in z-order relatively to given control. I need this in order to be able to temporary bring the control to front (Control.BringToFront()) and being able to place it back later in the original order. Any suggestions are highly appreciated! Thank you Andrey
7
2325
by: Sky | last post by:
What I have currently: I have a user control called mod_container.aspx that is basically two divs -- the top a toolbar, that expands/collapse the second div which can contain other modules/controls (eg a newsfeed, quick phonelist, login, etc.) But the controls end up too 'deep': it appears that it would be lighter/better if I could just...
4
2314
by: Brian W | last post by:
Hi All, I know this is a dumb question, but I'll ask it anyway... How do you do client-side scripting with an ASP control? For example I have: <asp:hyperlink id="Hyperlink1" runat="server" NavigateUrl="~/" onclick="return false;">Home</asp:hyperlink>
6
14683
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm using the Imagebutton.Attributes.Add("onMouseOver","this.src = 'somepicture.jpg') and that works fine. I've tried some java script to change the...
3
1577
by: | last post by:
For a given web form, I want to know what the +simplest+ way to add an attribute to all of a particular control type on that page. For example, I might want to add an onClick attribute to all TextBoxes on the page, e.g. .Attributes.Add("onKeyUp", "dosomething(event);"); I know that I can create a custom user control or custom control or...
5
6959
by: HL | last post by:
Hi, I need to enumerate windows and find the sum of the rect of all the windows of a specific application. In C++, I use the APIs - 'EnumWindows , GetWindowRect and UnionRect to accomplish the same. How to perform the above in c#? Is PInvoke the only way to do it or Is there some inherent c# way?
8
1407
by: Dustan | last post by:
Can I make enumerate(myObject) act differently? class A(object): def __getitem__(self, item): if item 0: return self.sequence elif item < 0: return self.sequence elif item == 0: raise IndexError, "Index 0 is not valid."
0
11958
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the form controls so
2
6573
by: cloftis | last post by:
Using VS2003, VB and MSHTML, Using an HTMLSpanElement I want to enumerate the attributes of a SPAN tag. 1 'For testing sake 2 Dim strMarkup as String = "<span attr1='somevalue' attr2='somevalue' attrN='...'>markup</span>" 3 Dim objSpan As HTMLSpanElement = browser.Document.createElement("span") 4 objSpan.innerHTML =...
0
7628
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7938
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8145
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7694
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5245
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3679
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.