When the control is rendered to html, it might have a diferent ID, the property is named
ClientID
, but if you want just to change all controls, just place them inside a container and check for them.
on the asp.net would be like this:
<div id="mycontainer" runat="server">
<asp:Label runat="server" ID="label1" Text="label 1"></asp:Label>
<asp:Label runat="server" ID="label2" Text="label 2"></asp:Label>
<asp:Label runat="server" ID="label3" Text="label 3"></asp:Label>
<asp:Label runat="server" ID="label4" Text="label 4"></asp:Label>
<asp:Label runat="server" ID="label5" Text="label 5"></asp:Label>
<asp:Label runat="server" ID="label6" Text="label 6"></asp:Label>
<asp:Label runat="server" ID="label7" Text="label 7"></asp:Label>
<asp:Label runat="server" ID="label8" Text="label 8"></asp:Label>
</div>
and the code behind (c# in this case) is like this:
protected void Page_Load(object sender, EventArgs e)
{
foreach (var control in mycontainer.Controls)
{
Label label = control as Label;
if (label != null) label.Text = "Found it!";
}
}
That should work.
Please notice that if you attach any other logic to your page, you might want to do that in the
PreRender
event, instead of the
Page_Load
.
Hope it helps.