Specify Image location in Web.Config

M

Manny Chohan

Hello Guys,

Just curious over the fact if i can store Image Location in Web.Config and
then how can i extract that location in HTML

<td style="width:1%" align="left" valign="middle">
<img alt="" src="<%# image Location'
%>/Images/lhw_logo_black.jpg" id=headerImage runat=server /></td>
<td style="width: 1%" align="right" valign="middle">

Is it possible to do something like this or not? I am developing in C#2.0 .
I am trying to avoid this in Codebehind.

Thanks

Manny
 
B

bruce barker

just create a function in you base page like ImagePath(string s) then you can
use it in a binding expression (which will require a bind) or standand.

<img src='<%# ImagePath("myImage.gif")%>' runat="server"/>
<img src='<%= ImagePath("myImage.gif")%>' />

another option is a prerender handler that walks the control collection
(requires each image have a runat=server). and update the src.


-- bruce (sqlwork.com)
 
P

Peter Bromberg [C# MVP]

in Page ASPX:
<asp:Image ID="Image1" runat=server ImageUrl = '<%$ appSettings:myImage1
%>' />

in web.config:

<appSettings >
<add key="myImage1" value="~/images/check2.gif"/>
</appSettings>

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: htp://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
 
M

Manny Chohan

Thanks Bruce. How about if the ImagePath is located in a Class file under
your App_Code folder?
 
M

Manny Chohan

I meant the Function ImagePath. Thanks

Manny Chohan said:
Thanks Bruce. How about if the ImagePath is located in a Class file under
your App_Code folder?
 
B

bruce barker

sure, just make it a public static, but its a good practice to have a base
page, that your pages inherit from.


-- bruce (sqlwork.com)
 
M

Manny Chohan

Thanks. It works.

bruce barker said:
sure, just make it a public static, but its a good practice to have a base
page, that your pages inherit from.


-- bruce (sqlwork.com)
 
M

Manny Chohan

Thanks Peter. In your example, you have specified the image name in the web
config. can we not do that and instead have the Web.Config return base
location of the image i.e http://servername/appname/images

and in HTML:
<asp:Image ID="Image1" runat=server ImageUrl = '<%$ appSettings:myImage1
%>/imagename.jpg' />

I have tried various combos and they didnt work. Can you please assist?

Thanks

Manny
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top