Looping over my WebControls

J

Jim Bancroft

Hi everyone,

I'm struggling with something.....I'd like to loop over all of my page's
HyperLink controls, and I'm not sure how to do it.

Here's what I'm looking for, in pseudocode:

foreach (System.Web.UI.WebControls.HyperLink hLink in this.Controls)
{

hLink.Target= "fill in value here using custom algorithm";

}

Anyone know of a good way to do this? Thanks very much.
 
G

Guest

try yhis.....
For Each cntrl As Control In e.Item.Cells(i).Controls
If TypeOf cntrl Is System.Web.UI.WebControls.HyperLink
Then
CType(cntrl, HyperLink).Target= "yahoo.com"
End If
Next



--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
 
S

Shuvro Mazumder [MSFT]

Yes, the recursive call is the way to go, except that you might want to code
the type checking as

else if ( cntrl is System.Web.UI.Controls.HyperLink )
instead of
else if ( cntrl.GetType().FullName.IndexOf ("HyperLink") !=-1 )

--
- Shuvro
SDE, MSFT

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
 
G

Guest

I believe you meant: System.Web.UI.WebControls.HyperLink (instead of
System.Web.UI.Controls.HyperLink). Thanks for the suggestion. I modified
the code sample accordingly.
 
S

Shuvro Mazumder [MSFT]

Yes, I meant System.Web.UI.WebControls.HyperLink. Note that this will not
work if the anchor object <a> is used with (runat=server). In that case,
you'll want to change your if loop to include a type checking for this
object.

If the object is not server side, I believe I saw a client side javascript
example that does the same recursively.

--
- Shuvro
SDE, MSFT

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top