How show a master page reference an image file?

  • Thread starter Thread starter AAaron123
  • Start date Start date
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
 
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
 
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. :-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************

Hillbilly said:
Did you know we can add runat="server" to any HTML element and it will
function as a Control?
 
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).

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
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?
 
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
 
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
 
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.
 
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
 
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.
 
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.
 
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.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
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.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
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.
 
Back
Top