How show a master page reference an image file?

A

AAaron123

I have a master page that contains:

<img src="Images/abc.gif"...

If the contents page is in the root directory with the master page the image
shows when that page shows.

However, if the context page is in a folder the image does not show when
that page shows.

I don't know how to fix this.

Is it possible to fix it?





Thanks
 
H

Hillbilly

Did you know we can add runat="server" to any HTML element and it will
function as a Control?

AAaron123 said:
I had tried tilde but realize now I have to use a server control

Thanks
 
G

Gregory Beamer

Most, not any. It has to have an analog in the HTML controls to work that
way. This covers pretty much everything, if not everything, that is visible,
along with many non-visible "controls". You will find, however, that things
like <pre runat="server"></pre> has no meaning. There are others, as well
.... I just picked one that is fairly obvious. :)



Hillbilly said:
Did you know we can add runat="server" to any HTML element and it will
function as a Control?
 
G

Gregory Beamer

I see you have the answer, but the reason this works with the image control
(asp:Image) and not with the standard HTML is the RenderClientPath() method
(if I remember the name correctly). That is what turns the path into an
absolute path from a tilde. It is also why you cannot use the tilde with the
standard HTML image "control" (tag).
 
A

AAaron123

No I did not know that.

And the attributes are the ones for the HTML element or the ones for the
control.

Is it: <img runat="server" ImageUrl=...

thanks


Hillbilly said:
Did you know we can add runat="server" to any HTML element and it will
function as a Control?
 
A

AAaron123

I tried to read about RenderClientPath but could find no reference in the
help or Google. I tried a few variations but didn't find it.

I'll keep my eye open for something like that.

Thanks
 
A

AAaron123

Mark Rae said:
No. The runat="server" tag doesn't convert an HtmlControl into a
WebControl - it simply means that it is accessible server-side.

<img runat="server" src="Images/abc.gif"...

Thanks
 
G

George

I would advise agains converting every image to the server object just
because you need to resolve ~ in your src path.
It's easier to do things right and simply put absolute reference (As opposed
to relative reference to image)

so <img src="Images/abc.gif">

needs to be
<img src="/MyProject/Images/abc.gif">

Then you will not have problems.
If you need your code to run from root (meaning that your project will be
moved to root once in production and there will be no /MyProject/ then there
are several options available depending what you using IIS or embedded web
server (aka ASP.NET Development Server)

Here is how to run project from Root if you using ASP.NET Development Server

1. Start ASP.NET Development Server manually on some port (I use 103)
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE"
/port:103 /path:c:\projects\StoreSupport
where path is the path to you project

2. Change in you properties for your solution the start option to 'Custom
server', Base url: http://localhost:103/

PS: if you shutdown your PC (or stop ASP.NET Development Server) you need to
start it yourself. VS will not do it automaticly.


George.
 
A

AAaron123

Seems to me that depending on which page is showing the src needs to be
either Images/abc.gif or ../Images/abc.gif

The second is needed when the page's .aspx file in a folder. (the img is in
the .master that is not in a folder (I guess that's being in the root)

I don't understand your suggestions. Do they apply when I upload to an ISP?

Thanks for your interest
 
A

AAaron123

Mark Rae said:
There's no need to do any of the above. The tilde server-side shortcut is
provided precisely to meet your sort of requirements...
thanks a lot
 
G

George

The Images/abc.gif or ../Images/abc.gif both are relative paths
That means that they are relative to the current page.
For example in page http:///www.mysite.com/myage.aspx image with
src=Images/abc.gif will refer to http:///www.mysite.com/images/abc.gif
in page http:///www.mysite.com/myfolder/myage.aspx it will refer to
http:///www.mysite.com/myfolder/images/abc.gif

Absolute reference like /Images/abc.gif (notice / in front) will always be
an absolute path and refer to http:///www.mysite.com/images/abc.gof no
matter which page it's on.

So you need to reference your images with <img
src="/MyProject/Images/abc.gif"> during your development. Problem is when
you move your code to production which might not have /MyProject/ folder.

I have outlined steps to develop your site from root. Then your project will
not depend on the Project name.

George.
 
G

George

But tilde thing only works with server objects.
It would be totally wrong to make an object out of every small thing (like
image)..

George.
 
G

Gregory Beamer

You can find it by using Reflector over the actual Microsoft DLLs. It is a
private method on the class. I doubt you will find much information on the
web, as it is private.
 
A

AAaron123

Thanks for helping

Gregory Beamer said:
You can find it by using Reflector over the actual Microsoft DLLs. It is a
private method on the class. I doubt you will find much information on the
web, as it is private.
 
G

George

It would be totally wrong to make an object out of every small thing
I think perhaps you need to read up on the differences (such that there
are) between HtmlControls and WebControls...

HtmlControls and WebControls are different objects. They support different
properties and methods. But they are objects and in order to initialize the
page all objects that on a page must be allocated, initialized and other
bunch of methods called like LoadViewState......ASP.NET framework simply do
not care (and does not know a difference) between HtmlControls and
WebControls. Those are simply add-ons. You can create your own controls as
long as they based of System.Web.UI.Contol you will be able to place it on a
page. Even though HtmlControls do not keep ViewState the LoadViewState is
still called but simply does nothing.

ASP.NET framework choose not to create gazilion of objects out of every HTML
tag on a page and allowed developer to specify only those that are needed
(using runat=server). Simply because otherwise it will waste a lot of CPU
cycles for nothing.

Same here... If you do not have to create server object then do not do it. I
would not call inability to reference an image on the page a call to create
a server control out of every image on the page.
There are plenty (CPU friendly) ways to workaroung that problem. I suggest
to utilize those methods instead.



George.
 

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,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top