The following code will not display the image, it does show that an image is present but the image does not display. Any ideas?
<%# Page Language="C#" MasterPageFile="~/Main_MP.master" AutoEventWireup="true" CodeFile="Phone.aspx.cs"
Inherits="Phone1" Title="Talk & Txt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<img src="Talk & Txt Page.jpg" alt="Smiley face" height="42" width="42" />
<br />
<asp:Label ID="lblCounter" runat="server" Visible="False" Font-Bold="True" Font-Names="Calibri" Font-Size="Small" ForeColor="#C00000"></asp:Label></div>
</div>
</asp:Content>
The unescaped ampersands may be causing your issue.
Rename the image file to TalkAndTxtPage.jpg - All files linked via URL, including images, are best named without using reserved or unsafe characters (both space (" ") and ampersand ("&") fit into this category). Reference - http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
Then do this (you also had a bad <div> tag):
<%# Page Language="C#" MasterPageFile="~/Main_MP.master" AutoEventWireup="true" CodeFile="Phone.aspx.cs"
Inherits="Phone1" Title="Talk & Txt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<img src="TalkAndTxtPage.jpg" alt="Smiley face" height="42" width="42" />
<br />
<asp:Label ID="lblCounter" runat="server" Visible="False" Font-Bold="True" Font-Names="Calibri" Font-Size="Small" ForeColor="#C00000"></asp:Label>
<div>
</div>
</asp:Content>
Replace the spaces in the image URL (ie, the 'src') attribute with %20.
You can't have spaces in a URL, but %20 should work.
Does that image is in the same directory as the page, otherwise you need to give the full relative path
Remove the spaces from the image name.
<img src="Talk-Txt-Page.jpg" alt="Smiley face" height="42" width="42" />
Also, where is the image located in relation to the page? You might need to point to the directory.
<img src="/images/Talk-Txt-Page.jpg" alt="Smiley face" height="42" width="42" />
Hope this helps!
this alone with an image named Talk & Txt Page.jpg works on my side.
I see a couple of ending div tags in your code that do not have a beginning div
Related
I have a web.config key :
<add key="IMGSRC" value="http://localhost" />
I want to use the value of this key along with the path of the image concatenated to in an aspx page. I'm aware that I can get to root folder by simply saying "../ImagesFolder" , but my website has parent path disabled because of security concerns. So now I need to work around it.
I need something like this (Here are a few things I tried after looking up the internet and which did not work.):
1) <img id="Img19" runat="server" alt="Admin" src='<%#ConfigurationSettings.AppSettings["IMGSCR"] %>' />
2) <img id="Img19" runat="server" alt="Admin" src='<%#ConfigurationSettings.AppSettings["IMGSCR"] + "/ImagesFolder/img.jpeg" %> ' />
3)
<img id="Img19" runat="server" alt="Admin" src="<%#ConfigurationSettings.AppSettings["IMGSCR"] %> " + "/ImagesFolder/img.jpeg" />
Also I tried this:
I declared a variable Path on Page_Load
Path = System.Configuration.ConfigurationManager.AppSettings["RootforIMG"].ToString();
and then on aspx page I tried using it as
<img id="Img19" runat="server" alt="Admin" src="<%=Path %> " + "/ImagesFolder/img.jpeg" /> but this as well is no good.
Can you try something like below?
<img id="Img19" runat="server" alt="Admin" src='<%= GetImageSource()%>' />
In code behind
public string GetImageSource()
{
return ConfigurationManager.AppSettings["IMGSCR"] + "/ImagesFolder/img.jpeg";
}
The relative path of images should work:
Relative path can be as per your page location i.e: '../IMages/img.jpg' or 'images/img.jpg'
try this :
<img id="Img19" runat="server" alt="Admin" src='ImagesFolder/img.jpeg' />
For controls with runat="server" attribute you do not need any special code to map a path relative to web site root:
<img id="Img19" runat="server" alt="Admin" src"~/ImagesFolder/img.jpeg" />
The path ~/ImagesFolder/img.jpeg will be resolved replacing ~ with the root folder of your web-site.
If to resolve path you need some kind of logic (for example you need to call a function) then you can use this:
<img src'<%= ResolveImageName() %>' />
Do not forget that URL must be proper encoded.
I want to have 4 links in the sidebar of master page which every other form (content page) in my web application inherits.
<table>
<tr>
<td width= "150px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<asp:Menu runat="server" ID="MainMenu1" CssClass="MasterContent" StaticSubMenuIndent="30px">
<Items>
<asp:MenuItem Text="My Software" NavigateUrl="~/MySoftware.aspx"></asp:MenuItem>
<asp:MenuItem Text="Check Out" NavigateUrl="~/CheckOut.aspx"></asp:MenuItem>
<asp:MenuItem Text="View Shopping Cart" NavigateUrl="~/ShoppingCart.aspx"></asp:MenuItem>
<asp:MenuItem Text="Continue Shopping" NavigateUrl="~/Start.aspx"></asp:MenuItem>
</Items>
</asp:Menu>
</asp:ContentPlaceHolder>
</td>
<td width="900px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
This is the content in the master page as you can see there are 4 menu items i tried to form as sidebar and i tried to inherit in home.aspx(one of the content pages) as follows:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Start.aspx.cs" Inherits="WebStore._Start"
MasterPageFile="~/Webstore.Master" %>
<asp:Content ID="StartSideBar" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
But unfortunately the sidebar is not at all getting displayed. I know i'm doing fundamentally wrong some where. My intention is to have web pages to have sidebar like this. It is a screenshot of my intended page.
Can some one guide me through this.
Thanks in anticipation
The way you have it set up, your home.aspx file is clobbering your menu links because it is defining the content of ContentPlaceholder1 to be empty (or something else at any rate), which is overriding the menu links you put in your MasterPage inside the same content holder. The way MasterPages and content pages work is that the MasterPage defines a location (a ContentPlaceholder) for the content page (e.g., home.aspx) to load content into. But you have put actual content you want to keep inside a ContentPlaceholder on your MasterPage--which means that any content page (again, like home.aspx) that defines content for ContentPlaceholder1 (like you do with StartSideBar) is going to override anything defined inside ContentPlaceholder1 on the MasterPage--in this case, your menu links.
If you want your menu links to remain constant on every content page, then you should move them out of ContentPlaceholder1 on the MasterPage and make them just markup on the MasterPage (in fact, you should probably remove ContentPlaceholder1 altogether). The easy way to do this is to comment out the ContentPlaceholder tag itself like this:
<table>
<tr>
<td width="150px">
<%--<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">--%>
<asp:Menu runat="server" ID="MainMenu1" CssClass="MasterContent" StaticSubMenuIndent="30px">
<Items>
<asp:MenuItem Text="My Software" NavigateUrl="~/MySoftware.aspx"></asp:MenuItem>
<asp:MenuItem Text="Check Out" NavigateUrl="~/CheckOut.aspx"></asp:MenuItem>
<asp:MenuItem Text="View Shopping Cart" NavigateUrl="~/ShoppingCart.aspx"></asp:MenuItem>
<asp:MenuItem Text="Continue Shopping" NavigateUrl="~/Start.aspx"></asp:MenuItem>
</Items>
</asp:Menu>
<%-- </asp:ContentPlaceHolder>--%>
</td>
<td width="900px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
You will also have to remove the ContentPlaceholder reference from your content page as well, or you will get a compliation error (because you removed it from the Master, it can't exist in the content page--but that's okay, the MasterPage now has the links you want):
<%# Page Title="" Language="C#" MasterPageFile="~/Webstore.master"
AutoEventWireup="true" CodeFile="Start.aspx.cs" Inherits="Start" %>
<%--<asp:Content ID="SideBarStart" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>--%>
I've tried both snippets below. Nothing. I've tried <%#, <%=, and <%. Nothing. So I'm stuck.
<div style="background-color:Gray; color:white; text-align:center; width:100%;">
<asp:HyperLink ID="HyperLink1" Target="_blank" NavigateUrl='<%= Server.HtmlEncode(String.Format("~/ShowHistory.aspx?section={0}&jobnumber={1}", "APQP Header", "101244")) %>' runat="server">Show Updated History</asp:HyperLink>
<asp:HyperLink Target="_blank" NavigateUrl="~/ShowDeletedHistory.aspx" ID="HyperLink2" runat="server">Show Deleted History</asp:HyperLink></div>
<br />
<div style="background-color:Gray; color:white; text-align:center; width:100%;">
<asp:HyperLink ID="HyperLink1" Target="_blank" NavigateUrl='<%= String.Format("~/ShowHistory.aspx?section={0}&jobnumber={1}", "APQP Header", "101244") %>' runat="server">Show Updated History</asp:HyperLink>
<asp:HyperLink Target="_blank" NavigateUrl="~/ShowDeletedHistory.aspx" ID="HyperLink2" runat="server">Show Deleted History</asp:HyperLink></div>
<br />
Try <%# ... %> and call this.DataBind() (or Me.DataBind()) when your page loads.
Server controls cannot contain this type of tags. The reason is that "<%= %>" is basically equal to Response.Write, which itself executes after the page has gone through its lifecycle, when the response is already constructed. If you use it when setting a value of a server-side control property, this value has to be resolved when (or a little after) parsing the page markup. This is the reason you cannot use "<%= %>" in a server control.
If it was a normal html tag, it would work, but the virtual URL would not.
Is there a reason you're not setting the NavigationUrl in code? It would look much nicer to me.
I never saw that problem and I have no idea what is causing it.
I got something like this code in my masterpage
<div class="myClass1">
<a href="~/#link" runat="server" title=" <%$ Resources: myRess1 %>">
<asp:Literal runat="server" Text="<%$ Resources: myRess1 %>" /><br />
<img class="myClass2" src="/MasterPage/images/myGif.gif" width="19" height="12" alt="" />
</a>
</div>
when I browse a page that using this master page, the code become
<div class="myClass1">
<a href="#link#link" title="myTitle">
myTitle<br />
<img class="myClass2" src="/MasterPage/images/.gif" width="19" height="12" alt="" /><br />
</a>
</div>
why does the link double itself?
if I put something like default.aspx instead of #link, it work perfectly.
The reason why I'm using "~/" is because the master page is located somewhere else, if I don't put ~/ it make the link as /masterpage/#link which is invalid
The ~/ should not be necessary. Just use #link
'~' can be used only with server controls and not with html controls. You should just use href="#link".
for now I changed my
<a href="~/#link" runat="server" title=" <%$ Resources: myRess1 %>">
to
<a href="#link" title="<%=GetLocalResourceObject("myRess1 ") %>">
and it's working fine but if someone could tell me why with runat="server" screw up the #link, that would be good to know
When I use a ASP:Calendar control, and give it an ID:
<asp:Calendar runat="server" ID="MyCal" />
It looks like this in the rendered html:
<table id="NameMangled_MyCal"... />
And I can access the element by ID in javascript like this:
var cal= document.getElementById("<%= MyCal.ClientID%>")
However, When I make a custom user control that has-a calendar:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div>
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>
And then give it an ID when I add it to my page...
<mvs:WeeklyEventsCalendar ID="WeeklyCal" runat="server" />
That ID doesn't show up anywhere in the rendered HTML. all I get is
<div> stuff </div>
When I want
<div id="NameMangled_WeeklyCal"> stuff <div>
What am I doing wrong?
UserControls only render their contents, nothing else. What you could do is
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div id="<%= this.ControlID %>">
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>