Looping over my WebControls

  • Thread starter Thread starter Jim Bancroft
  • Start date Start date
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.
 
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__
---_,>/'_------
(_) \(_)
 
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.
 
Thanks guys...I'll take these suggestions and run with them.

-Jim
 
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.
 
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

Back
Top