Server variables in ASP.NET Html code

A

A Traveler

Given i have some control which has an "ImageURL" property. If this property
is set, then the HTML code for the web control looks something like:

<mns:image id=MyImg runat=server ImageURL="images/somepath.jpg"></mns:image>

Given i have some server variable Session("AppRoot") which declares the full
path to the root of the application, for example
Session("AppRoot") = "http://www.someserver.com/myapp/"

Now is there any way i can put the AppRoot variable directly into the HTML
control for the mns:image control, rather than having to put code in the .vb
file to do something like
MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL

Could i somehow do SOMEthing like:

<mns:image id=MyImg runat=server
ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
</mns:image>
 
K

Karl

There are a number of things I don't understand.

1-
If this is your own server control, or you have access to the source, why
not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
class before the render? This way you don't have to worry about doing it
either at the page level or the codebehind. If you don't write your own
that inherits from this one.

2-
Does the AppRoot actually belong to the sesssion? it's specific to each
user?

3-
You can simply use ~ to denote the application root, ala:
ImageUrl="~/images/somepath.jpg"

4-
The answer to your question is no..but the solution in #1 will solve her
right up.

Karl
 
A

A Traveler

Well, i cannot code it into the code for the control, because the control is
made in a separate library meant ot be generic to NO app in specific.

I cannot use a Root path ("/" or "~") because the app does not root at the
root of the site.
The site's root is www.myserver.com/myapp, not www.myserver.com

Otherwise then i guess im just stuck having to alter the urls in the .vb
file then. Thats a little annoying. Itd be nice if you could somehow use
something like the databinding stuff to put out a server variable into
ASP.NET html code.
 
K

Karl

~ uses the virtual app..so it should be ~ should be equal to /myapp

and you could still make the code generic to no specific app (as it is now
actually, it's specific to apps at the root level so it isn't very
generic)...but ~ should do the trick.

Karl
 
A

A Traveler

Hmm, .. well, i tried using the ~ instead and taking out my code in .vb to
prepend the approot to the path, but it does not work with the ~.

Thanks though for the idea.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top