0

Let's say I have a Constants class defined in a .vb file as such:

Public Const myConst As String = "myID"

And in my page.ascx file I wish to do something like this:

...
<someControl ID="<%$ Constants.myConst %>" runat="server" />
...

This shields compilation errors all over the place.

I've attempted several combinations, including = or # instead of $, but none seem to work.

Note that I've read and do not believe this to be a duplicate of this answer, nor other similars.

Lundin
  • 174,148
  • 38
  • 234
  • 367
Sebastián Vansteenkiste
  • 2,105
  • 1
  • 17
  • 27

1 Answers1

1

I don't think this is even possible since Visual Studio use the ID to create an instance of that object in the .vb file. I would question the purpose of this but if you really need to I would suggest to generate a dictionary.

<someControl ID="ctrlName" runat="server" />

And in the init

Dim dic As New Dictionary(Of String, Control)

dic.Add(Constants.myConst, ctrlName)

Usually it's the other way around where the web page tells the dll which id/instance to use.

the_lotus
  • 12,421
  • 2
  • 33
  • 52