473,770 Members | 1,700 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 4547
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
4567
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
2342
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 enherit the uc_login.aspx directly off of the uc_container.aspx so that all modules have the same...
4
2326
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
14699
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 other control's visible property by changing is className, but that doesn't seem to work
3
1596
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 otherwise extend stuff with some work. I'm wondering if there's a quicker and dirtier way to do this...
5
6971
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
1420
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
11999
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
6598
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 = strMarkup
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2832
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.