Click to See Complete Forum and Search --> : Duplicate controls in ASP.NET


hoelzro
01-08-2007, 10:22 PM
I'm new to ASP.NET, and I'm making a website, the contents of which depend on data provided via GET. It's something like this:

<html>
<head>
string page; // retrieved via GET
</head>
<body>
<% if(page.Equals("1")) {
%> <asp:Label id="label" runat="server" Text="Label one" />
<% } else if(page.Equals("2")) {
%> <asp:Label id="label" runat="server" Text="Label two" />
<% } %>
</body>
</html>


Yes, I know the above example is trivial, and there's a "simple" way to solve it by writing different Text attributes based on page, but what I'm wondering is the following:

Is there a way to reuse a control name in a page if the two seperate instances won't appear together?

Thanks!

scottrickman
01-09-2007, 11:26 AM
...
<body>
<asp:Label id="label" runat="server" Text="Default Value" />
<%
switch (page)
{
case "1":
this.label.Text = "Label One";
break;
case "2":
this.label.Text = "Label Two";
break;
}
%>
</body>
...