controls as variables

  • Thread starter Thread starter Marc Miller
  • Start date Start date
M

Marc Miller

I have 10 hyperlinks on an .aspx page. Hyperlink1, hyperlink2, etc.
I want to reference them in a loop to set their visibility and targets.
What I think I want to do is
mylink = 'hyperlink' & i (i being 1 to 10)

and change the string into a hyperlink reference and then do
mylink.target = abc.aspx
mylink.visible = true

I'm an old FoxPro programmer, so I'm lost in finding help on
this.

TIA,
Marc Miller
 
1)Put them all into an array, and index into an array
2)Use FindControl method to get the individual hyperlink. This isn't all
that well performing, but may not matter in your case.

Btw, I recommend googling for questions like this, they've been answered
dozens of times.
 
Marc said:
I have 10 hyperlinks on an .aspx page. Hyperlink1, hyperlink2, etc.
I want to reference them in a loop to set their visibility and targets.
What I think I want to do is
mylink = 'hyperlink' & i (i being 1 to 10)

and change the string into a hyperlink reference and then do
mylink.target = abc.aspx
mylink.visible = true

Look at the FindControl() method. Basically you can do a loop like so:

For i as Integer = 1 to 10
Dim hl as HyperLink = FindControl("HyperLink" & i)
If Not hl is Nothing Then
hl.NavigateUrl = ...
...
End If
Next

Additionally, this article would be benefitial reading:
http://www.odetocode.com/Articles/116.aspx

hth

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Back
Top