Click to See Complete Forum and Search --> : Server Control ID


Liming
10-23-2003, 02:55 PM
Hi all,

Is there anyway to create Server Control ID dyanmically inside the page?

such as <asp:panel ID="ID<%=my_variable%>" runat="server"></asp:panel>?

This way, I'm getting an error...<%=my_variable%> is not a valid identifier.


I understand that I'm able to use a placeholder inside the page and dyamically
add an asp:panel to the placeholder inside Page_Load()..that works.... but
I'm just curious why the traditional ASP way doesn't work.

Thanks a lot

Dave Rothgery
10-23-2003, 02:55 PM
"Liming" <lmxu@yahoo.com> wrote in message
news:3f943f12$1@devx7.web.devx.com...
>
> Hi all,
>
> Is there anyway to create Server Control ID dyanmically inside the page?
>
> such as <asp:panel ID="ID<%=my_variable%>" runat="server"></asp:panel>?
>
> This way, I'm getting an error...<%=my_variable%> is not a valid
> identifier.
>
>
> I understand that I'm able to use a placeholder inside the page and
> dyamically add an asp:panel to the placeholder inside Page_Load()..
> that works.... but I'm just curious why the traditional ASP way
> doesn't work.

It doesn't work because when you create a tag in an ASP.NET page with
runat="server", you're effectively declaring a variable named whatever you
set the id attribute to. And variables without a name aren't really easy to
work with.

I'm pretty sure that if you had an HTML DIV tag (which is what a panel
renders as) without the runat="server" attribute, you would be able to set
the ID programattically. But as soon as you add the runat="server", your
VB.NET or C# code needs to know how to refer to that element.


--
Dave Rothgery
drothgery@alum.wpi.edu