Use variable within HTML with ASP.NET

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I have defined a global variable in a global_variables.vb module in my
ASP.NET application.

Now that this variable is defined, how do I reference it within the
HTML code of the ASPX page?

In classic ASP, I could do the following:
<%
dim lcImagePath
lcImagePath = "/mywebroot/images"
%>
....
<img src="<%=lcImagePath%>/image.gif">

How do accomplish this in ASP.NET?
Thanks in advance for the help!
Jason
 
Thanks for the info...

My question wasn't one specifically referring to images, but anything.
Would this method also work for the following classic ASP example:

<%
lcApplicationRoot = "/mywebroot"
%>
<a href="<%=lcApplicationRoot%>/default.asp">

Thanks again!
Jason
 
yes it is possible, for example

<% ...%>
<a href="<%# applicationpath %>/default.asp" />
 
I have a module file, global_variables.vb, that reads:
Module global_variables
Public GS_IMAGE_PATH
End Module

I can successfully reference this variable in any of the Code Behind
sections of any page, but when I try to use it in the HTML:
<td align="right" background="<%# GS_IMAGE_PATH%>/top_image.gif">

I get a compilation error stating that GS_IMAGE_PATH is undefined.

I found a section on Data Binding in a book and it said I needed to
call the DataBind() function from Code Behind (Page_Load for instance)
to evaluate this expression to it's value. The book mentions that it
must be an object or control for which the DataBind() function exists,
but this is simply a string. I can't execute the DataBind() function
against this string.

Can you help with this specific instance?
Thanks again for all of your posts!
 
Back
Top