473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Use variable within HTML with ASP.NET

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

Nov 19 '05 #1
4 1267
You can do the samething in asp.net also. but with slight change, for
example
<asp:Image id="myImage" runat="server"
ImageUrl='<%# DataView ( 0 ) ( "productPhotoURL" ) %>'>For more details,
http://authors.aspalliance.com/aspxt...pressions.aspx
--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"Jason" <ja*************@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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

Nov 19 '05 #2
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

Nov 19 '05 #3
yes it is possible, for example

<% ...%>
<a href="<%# applicationpath %>/default.asp" />
--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"Jason" <ja*************@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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

Nov 19 '05 #4
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!

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Thomas Matthews | last post by:
Hi, While coding programs, I cam about a conundrum regarding variables defined in an iterative loop. The issue is whether it is more efficient to factor the definition out of the loop or...
4
by: SamMan | last post by:
I have a .js file that receives a value from an html page. I'd like this value to be a global variable that all functions in the .js file can use. I have tried just declaring a var at the top of my...
4
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
4
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
1
SHOverine
by: SHOverine | last post by:
Recently my web host decided to "upgrade". This change rendered many of my pages useless and I am scrambling to fix the issues, so you may see several posts from me in the coming days. My first...
2
by: neeebs | last post by:
Hi, I'm not sure if this is a javascript problem per se, but here goes. I have an xsl document with a python function defined within a <script> block. Elsewhere in the xsl file, within a python...
2
by: RgeeK | last post by:
I'm seeing something which make me think I'm missing something about how global var's behave. I've defined a global string, right at the start of my .py file. outXMLfile = "abc" I define a...
9
by: mrcheeky | last post by:
Hi, I'm stuck, but it's almost working! From a html page, my javascript calls a server-side php script. The php reads a value from a server-side .txt file and passes it back as a javascript...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.