0

I am trying to retrieve a path string from my web config file and use that plus the file name to get the url of the image I need. I think it should be something like this:

<asp:Image ImageUrl ='<%# System.Configuration.ConfigurationManager.AppSettings["AppPath"] + "&Images/headerbk01.jpg"%>' runat ="server" width="983" height="265" />

Which gives me an empty string for the source.

Edit:

Now using this:

<asp:Image ImageUrl ='<%=System.Configuration.ConfigurationManager.AppSettings["AppPath"]+"&Images/headerbk01.jpg"%>' runat ="server" width="983" height="265" />

Produces this as html:

<img style="width: 983px; height: 265px;" src="<=System.Configuration.ConfigurationManager.AppSettings["AppPath"]+"&Images/headerbk01.jpg"%>"/>
3
  • Could you try an = instead of a # in the code? That may make a difference. Commented Jul 26, 2013 at 17:34
  • Thanks, Just tried that and no change, my src is till an empty string Commented Jul 26, 2013 at 17:36
  • I have tried string temp = System.Configuration.ConfigurationManager.AppSettings["AppPath"]; in the code behind page and it is picking up the value correctly Commented Jul 26, 2013 at 17:38

2 Answers 2

2

Something like this:

C#

<asp:Image ImageUrl='<%# System.ConfigurationManager.AppSettings["yoursetting"] + "&Images/headerbk01.jpg" %>' runat = "server" Width="983" height="265" alt="image1.jpg" />

VB.NET

<asp:Image ImageUrl='<%# System.ConfigurationManager.AppSettings("yoursetting") & "&Images/headerbk01.jpg" %>' runat = "server" Width="983" height="265" alt="image1.jpg" />
Sign up to request clarification or add additional context in comments.

5 Comments

It looks like it could be right but I just get: The type or namespace name 'ConfigurationManager' does not exist in the namespace 'System' (are you missing an assembly reference?) in my asp page. DO I somehow need to add an assembly reference in the asp page?
Ok corrected that issue System.Configuration.ConfirgurationManager.AppSettings
Question answered I guess
Unfortunately not, updated question as I am just getting an empty string for the image src
If the image is in a repeater or gridview then the hash is to be used to evaluate the function while otherwise an equals may work better just as something to note.
0

You need to bind data to the Image Control. Add an ID to the Image:

<asp:Image  ID="Image1" ImageUrl ='<%# System.Configuration.ConfigurationManager.AppSettings["AppPath"] + "&Images/headerbk01.jpg"%>' runat ="server" width="983" height="265" />

In the code behind add this code:

Image1.DataBind();

Or if it's okay with img, try this:

<img src='<%=System.Configuration.ConfigurationManager.AppSettings["AppPath"]+"&Images/headerbk01.jpg"%>'  style="width:983px; height:265px;" />

2 Comments

That doesn't help, the issue is that the code is not actually picking up the values from the web config and the src is just being set as the actual characters of the code.
Are you sure Image1.DataBind(); executed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.