Use variable within HTML with ASP.NET

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
 
J

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
 
S

Saravana

yes it is possible, for example

<% ...%>
<a href="<%# applicationpath %>/default.asp" />
 
J

Jason

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top