Programatically build a reference on a ASPX page using VB

My aspx page has many imagebuttons, Checkboxes, and Labels.

Using VB.net (aspx)
imagebutton1, imagebutton2......
checkbox1, checkbox2....
label1, label2....
What i need is a way to programmatically change the properties of these in a loop. We need an array name for each or a way to reference the names of each so I can operate in a FOR LOOP.
ie imagebutton(i), ie checkbox(i), ie label(i)
For example if I wanted to turn the visible property of imagebutton(20) to imagebutton(50) to false.
Since all objects are imagebutton1, imagebutton2, imagebutton3 etc. how can I programmatically reference the objects and assign their properties.
[743 byte] By [royspiegel] at [2007-12-16]
# 1
Hi,

Since you have other controls as well on the form it will not work if you try to loop through and set the property. If you only had ImageButton Controls on the WebForm then you could have done something like this:


for(int intLoop=20; intLoop <= 50; intLoop++)
{
Page.Controls[intLoop].Visible = true;
}

But since you have other controls, you would need to load the IDs of the ImageButtons for which you want to set visibility and then iterate through.


Hashtable htImageButtons = new Hashtable();
for (int intLoop=20; intLoop <=50; intLoop++)
{
htImageButtons.Add("imgButton" + intLoop, "imgButton" + intLoop);
}

for(int intLoop=0; intLoop < Page.Controls.Count; intLoop++)
{
string strControlType = Page.Controls[intLoop].GetType().ToString();
if (strControlType == "System.Web.UI.WebControls.ImageButton")
{
ImageButton objImageButton = (ImageButton)Page.Controls[intLoop];
if (htImageButtons.ContainsKey(objImageButton.ID))
{
objImageButton.Visible = false;
}
}
}

Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified