I know this is probably a stupid question but I can't find anything on here about it. I have a master page in the root of my solution explorer and just put an .aspx page in a new folder. The master page is referencing an image in another folder and when I preview the page, it's a broken image. What do I have to do to have the page load the image from a master page? Thanks
You must use relative path. Below is an example:
<asp:Image ImageUrl="~/Images/orderedList1.png" runat="server" />
<img src="~/Images/orderedList0.png" runat="server" />
Don't forget to add runat="server" if you don't use asp.net control
Well, by not posting the markup with the reference to the image, you leave us to guess what's happening.
But how about this: you only have a partial (relative) path to the image, and that path is not valid from the location of your aspx file.
Did I guess right?
You may be referencing the image with no path.
When a child page is loaded in a MasterPage, the "current" directory changes to the child page's directory. So the relative path has changed.
Related
nesting of image inside a LinkButton shows image on one page & doesn't show image on another page below are two sample code from two different pages in the same root director.It works fine on one page but on the other page is doesn't show any download image rather shows the text download in place of image.
I have done troubleshooting for sometime and replace the code also but it doesnt show download image for any reason on the second page..
<asp:LinkButton ID="lnkbtnDownload" runat="server" onclick="lnkbtnDownload_Click" meta:resourcekey="lnkbtnDownloadResource1">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" meta:resourcekey="imgDownloadResource1" />
</asp:LinkButton>
<asp:LinkButton ID="lnkbtnDownload" runat="server" onclick="lnkbtnDownload_Click" meta:resourcekey="lnkbtnDownloadResource1">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" meta:resourcekey="imgDownloadResource1" />
</asp:LinkButton>
HTML OUTPUT
HTML for above two code sample render as below
<img alt="Download" src="images/download.png" id="MainContent_imgDownload">
Download
Both Pages are in the same root directory...
The problem probably comes from a discrepancy in your resource files or missing a resource file completely for the second page. Obviously you have one for the first, but possibly not for the other which has different naming.
If you are using meta:resourcekey, there are some things you have to considerate.
Make sure that your local resource files meet the following criteria:
They are in an App_LocalResources folder.
The base name matches the page name.
For example, if you are working with the page named Default.aspx, the
resource files are named Default.aspx.resx (for the default
resources), Default.aspx.es.resx, Default.aspx.es-mx.resx, and so on.
The resources in the file use the naming convention
resourcekey."property". For example, key name Button1."Text".
Source: MSDN
I downloaded a media player control from the Net then added in my toolbox. Then I drag-and-dropped it to my web page but it's not working...
cc1:Media_Player_Control ID="Media_Player_Control1" runat="server"
MovieURL="./video/yaarian.wmv"
this is my code
Make sure that the path is correct
e.g.
remove ./ if video is located in the child folder named video
or use absolute path e.g. /pages/video/yaarian.wmv
Check the control registration tag and make sure you have the assembly loaded in your bin folder:
<%# Register TagPrefix="cc1" Namespace="MyApp.Controls" Assembly="MyApp" %>
Then, try the following:
<cc1:Media_Player_Control ID="Media_Player_Control1" runat="server"
MovieURL="~/video/yaarian.wmv" runat="server" />
I'm confused with ASP.NET relative path, please can someone help?
In a Master Page I gave a link label referencing:
Login
From the ASP.NET official documentation I read:
The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.
<asp:image runat="server" id="Image1"
ImageUrl="~/Images/SampleImage.jpg" />
With the Login markup, when I click the link from a page in the /Account folder, I'm redirected to:
/Account/~/Account/Login.aspx
Why? WHY?h
Because you're using it directly in markup, rather than in a server control. Something as simple as this should fix it:
<a runat="server" href="~/Account/Login.aspx">Login</a>
Basically, the ~ path reference needs to be translated on the server, since it's a reference to the server path of the application's base directory. Plain HTML markup isn't processed on the server, it's just delivered as-is to the client. Only server-processed code will translate the ~ path to what it resolves to.
use this command
<a href="<%=Page.ResolveUrl("~/product.aspx")%>" >Link To Products</a>
You can use ~ when refering to URLs inside ASP.NET Server Controls.
You are using it in a <a> tag which is just plain html that doeesn't know anything about ~ . use '"/Images/SampleImage.jpg"' instead
I have a master page with links to other pages in the site. Those links use tilde paths (like "~/dir1/page2.aspx"). On most of the pages in the site that use this master page, there is no problem.
The problem only occurs on a few pages that use the master page. The links are VERY wrong; it tries to use the ~ as part of the link (so they are "http://server.domain.com/~/dir1/page2.aspx").
It's as if it is treating the tilde as a literal under certain circumstances.
Sounds like you're not properly resolving the URLs.
Are you writing ResolveUrl("~/")?
Also make sure that if you use ~/ that your controls are runat="server".
I just had this issue and the answer that worked best for me was to use the asp:Hyperlink control:
<asp:HyperLink ImageUrl="/Images/Logo.PNG" runat=server NavigateUrl="~/Default.aspx" />
I have a page login.aspx in a folder which is linked to masterpage. In the page load event of masterpage I have added some styles. When I redirect to login.aspx, it is just not able to get the styles from the masterpage's pageload event. I analysed the problem found that because my login.aspx is not in root folder, but in a folder which is inside root folder.
How do I run masterpage's pageload event in login.aspx?
You can place all your style sheets in a folder structure as follows:
App_Themes/Style/mystylesheet.css
Then in your content ASPX pages, just add Theme="Style" to the page directives and ASP.NET will automatically resolve it for every page that you have :-)
I assume you're talking about CSS stylesheets, and not ASP.NET styles (themes).
In that case, you can using a tag like the following from your Master page:
<link runat="server" rel="Stylesheet" href="~/scripts/common.css"
type="text/css" />
Or you can insert the same tag programmatically from your Page_Load() handler. However, in that case, it's best if you add the HtmlLink control to the Head control. Alternatively, you can add an ID to the control and use Visible="True" to control whether it appears in the generated markup.
If the code works when you move the code to your templatized page (not the but the one that uses it) then it suggests that you are using a relative link for the stylesheet.
I'd recommend using a relative URL off the root (something in the form of "/stylesheet.css") so that when you have pages that use the template, but in a subdirectory, it can resolve the stylesheet correctly.
The problem is that the section of the markup is located in the Master Page, so the reference to the StyleSheet cannot be made
Dim link As New HtmlLink
link.Href = "LocationOfStyleSheet.css"
link.Attributes.Add(HtmlTextWriterAttribute.Rel.ToString(), "stylesheet")
Page.Header.Controls.Add(link)