I am struggling to set ImageURL in a asp:image control. I am setting it to a URL from another site, at the moment I have several versions of the image trying to get one to work bellow is my code and the output.
Function used in images bellow
Function BuildLogoPath() As String
Return ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg"
End Function
ASP.net Code in page
<asp:Image ID="imgFav" runat="server" ImageUrl='<%: ConfigurationManager.AppSettings("WebPath") & "img/favicon.ico" %>' /><br />
<asp:Image ID="Image2" runat="server" ImageUrl='<%= ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg" %>' />
<asp:Image ID="Image3" runat="server" ImageUrl='<% ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg" %>' />
<asp:Image ID="Image4" runat="server" ImageUrl='<% Response.write(ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg") %>' />
<asp:Image ID="imgLogo" runat="server" ImageUrl='<%# BuildLogoPath() %>' /><br />
<asp:Image ID="Image5" runat="server" ImageUrl='<%= BuildLogoPath() %>' />
<asp:Image ID="Image6" runat="server" ImageUrl='<% BuildLogoPath() %>' />
<asp:Image ID="Image7" runat="server" ImageUrl='<% response.write(BuildLogoPath()) %>' />
<%= ConfigurationManager.AppSettings("WebPath") & "img/favicon.ico" %><br />
<%= ConfigurationManager.AppSettings("WebPath") & "/img/main/logo.jpg" %>
Output:
<img id="ContentPlaceHolder1_imgFav" src="<%:%20ConfigurationManager.AppSettings("WebPath")%20&%20"img/favicon.ico"%20%>"><br>
<img id="ContentPlaceHolder1_Image2" src="<%=%20ConfigurationManager.AppSettings("WebPath")%20&%20"/img/main/logo.jpg"%20%>">
<img id="ContentPlaceHolder1_Image3" src="<%%20ConfigurationManager.AppSettings("WebPath")%20&%20"/img/main/logo.jpg"%20%>">
<img id="ContentPlaceHolder1_Image4" src="<%%20Response.write(ConfigurationManager.AppSettings("WebPath")%20&%20"/img/main/logo.jpg")%20%>">
<img id="ContentPlaceHolder1_imgLogo" src=""><br>
<img id="ContentPlaceHolder1_Image5" src="<%=%20BuildLogoPath()%20%>">
<img id="ContentPlaceHolder1_Image6" src="<%%20BuildLogoPath()%20%>">
<img id="ContentPlaceHolder1_Image7" src="<%%20response.write(BuildLogoPath())%20%>">
http://office.logma.biz/onefit.com.jamie/img/favicon.ico<br>
http://office.logma.biz/onefit.com.jamie//img/main/logo.jpg
As you can see the code is working fine when not not in the image control.
The simple answer is that you can't use <% and %> inside <asp: .. /> tags. You have two options:
Set it programmatically from code-behind:
imgFav.ImageUrl = Me.BuildLogoPath()
Render a normal <img> tag in the HTML instead:
<img src='<%= BuildLogoPath() %>' />
Related
i use imagebutton in datalist and set codeexpression :Eval("PictureUrl", "ProductImages\thumb_{0}") and runtime display submitquery.
<asp:DataList ID="DataList1" runat="server" DataKeyField="pid"
DataSourceID="SqlDataSource1">
<ItemTemplate>
pname:
<asp:Label ID="pnameLabel" runat="server" Text='<%# Eval("pname") %>' />
<br />
pprice:
<asp:Label ID="ppriceLabel" runat="server" Text='<%# Eval("pprice") %>' />
<br />
publisher:
<asp:Label ID="publisherLabel" runat="server" Text='<%# Eval("publisher") %>' />
<br />
writer:
<asp:Label ID="writerLabel" runat="server" Text='<%# Eval("writer") %>' />
<br />
<asp:ImageButton ID="ImageButton7" runat="server"
ImageUrl='<%# Eval("PictureUrl", "ProductImages\thumb_{0}") %>' />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dbpath %>"
SelectCommand="SELECT [pname], [pprice], [PictureUrl], [gid], [storeid], [publisher], [writer], [pid] FROM [tblproduct]">
</asp:SqlDataSource>
output one record:
pname:
<span id="ContentPlaceHolder1_DataList1_pnameLabel_0">تکنیک عکاسی</span>
<br />
pprice:
<span id="ContentPlaceHolder1_DataList1_ppriceLabel_0">125000 </span>
<br />
publisher:
<span id="ContentPlaceHolder1_DataList1_publisherLabel_0">اسرار دانش</span>
<br />
writer:
<span id="ContentPlaceHolder1_DataList1_writerLabel_0">نصرالله کسرائیان</span>
<br />
<input type="image" name="ctl00$ContentPlaceHolder1$DataList1$ctl00$ImageButton7" id="ContentPlaceHolder1_DataList1_ImageButton7_0" src="ProductImages%09humb_~/image/tecnikakasi.jpg" />
You got the correct HTML rendered
<asp:ImageButton ID="ImageButton7" runat="server"
ImageUrl='<%# Eval("PictureUrl", "ProductImages\thumb_{0}") %>' />
will produce input tag with type=image
<input type="image" name="ctl00$ContentPlaceHolder1$DataList1$ctl00$ImageButton7" id="ContentPlaceHolder1_DataList1_ImageButton7_0" src="ProductImages%09humb_~/image/tecnikakasi.jpg" />
The problem is ProductImages%09humb_~/image/tecnikakasi.jpg not exists. It may be wrong.
Check the relative path rendered.
Try
ImageUrl='<%# Eval("PictureUrl", "~/ProductImages/thumb_{0}") %>'
It is displaying "SubmitQuery" because your image is not being loaded. If your writer alternate text, then alternate text will be displayed.
You can view source of the generated html and check the path of the image and try to correct it for resolving this problem.
ImageUrl='<%# Eval("PictureUrl", "{0}") %>'
I have the following code on a .aspx file. If I comment out the ModalPopupExtender code works fine.:
<cc1:ModalPopupExtender BehaviorID="mdlPopup" runat="server" TargetControlID="btn"
ID="mdl1" PopupControlID="pnlPopup" OkControlID="LinkButton1" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server" CssClass="confirm-dialog" Style="display: none;">
<div class="inner">
Work Order #: <asp:TextBox ID="txtWorkOrder" runat="server" Width="285" Text=""></asp:TextBox><br /><br />
Please Enter Corrective Actions<br />
<asp:TextBox ID="TextBox2" runat="server" Height="150" Width="285" TextMode="MultiLine"
Text=""></asp:TextBox>
<asp:Button ID="btnOK" runat="server" Font-Bold="true" Text="Submit" OnClick="click"
Width="150" />
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="close" OnClick="cancel" />
</div>
</asp:Panel>
<asp:Button ID="btn" runat="server" Style="display: none;" />
<asp:Label ID="id" runat="server" Text="Label" Visible="false"></asp:Label>
The problem that I am having is that the page just hangs when I have this code in the .aspx file. Is there anything I should do. It does not even get to the Page_Load.
I am calling this page that has the above code with the following:
string url = "Alerts.aspx?";
url += "ID=" + id.Text;
Response.Redirect(url);
I have created an ASP.NET page with an AJAX Accordion control. Within on the panes are several controls, some of which I've placed inside a Panel control, for various reasons.
However, controls which are on the page AFTER the closing tag for the panel are appearing INSIDE the panel when the page is rendered. For the life me I can't figure out why, and it's driving me crazy! Even clicking on the header of the Accordion Pane after the one containing the panel doesn't cause the Pane to expand, which it did before I added the Panel, seemingly because even IT is behaving as if it's within the Panel!
Any ideas what I'm doing wrong? How can I make the page believe that the panel ends!!?
<asp:Accordion ID="accQuestionnaire" runat="server" RequireOpenedPane="false" ContentCssClass="AccordionContent" HeaderCssClass="AccordionHeader" FadeTransitions="true"
transitionduration="250" HeaderSelectedCssClass="AccordionSelected" SelectedIndex="0" SuppressHeaderPostbacks="true" >
<Panes>
<%--START OF Tristan Link Pane (0)-------------------------------------------------------------%>
<asp:AccordionPane ID="pnTristanLink" runat="server" ContentCssClass="AccordionContent" ViewStateMode="Enabled" >
<Header>
Tristan Link
</Header>
<Content>
<div class="centrebuttonsdiv" >
<asp:Button ID="btnSearchTristan" runat="server" CssClass="largebutton" Text="Search Tristan" /><br />
</div>
<asp:Panel ID="pnlTristanSearch" runat="server" CssClass="panel" >
<div class="leftdiv"> <%--Matching Tristan results--%>
<asp:FormView ID="fvTristanSearch" runat="server" CssClass="FormView" >
<ItemTemplate>
<asp:Label ID="lblTristanSearchLabel" runat="server" CssClass="fieldtitle" Text="The information from Tristan for this Case Number is:" /><br /><br />
<asp:Label ID="lblAnimalNameLabel" runat="server" CssClass="fieldtitle" Text="Horse Name: " />
<asp:Label ID="lblAnimalName" runat="server" Text='<%# Eval("PetName") & " " & Eval("ClientNameLast") %>' /><br />
<asp:Label ID="lblGenderLabel" runat="server" CssClass="fieldtitle" Text="Sex: " />
<asp:Label ID="lblGender" runat="server" Text='<%# Eval("L_GenderDesc") %>' /><br />
<asp:Label ID="lblBreedLabel" runat="server" CssClass="fieldtitle" Text="Breed: " />
<asp:Label ID="lblBreed" runat="server" Text='<%# Eval("L_BreedDesc") %>' /><br />
<asp:Label ID="lblDOBLabel" runat="server" CssClass="fieldtitle" Text="DOB: " />
<asp:Label ID="lblDOB" runat="server" Text='<%# Eval("PetDOB", "{0:d}") %>' /><br /><br />
</ItemTemplate>
</asp:FormView>
</div>
<div class="rightdiv">
<br /><br />
<asp:Label ID="lblUnmatchedAppointments" runat="server" Text="Appointments for this horse with no Colic Study details:" Visible="false" /><br />
<asp:ListBox ID="lstUnmatchedAppointments" runat="server" DataSourceID="SQLUnmatchedAppointments" DataTextField="AppointmentDate" DataTextFormatString="{0:d}" DataValueField="AppointmentID"
Visible = "False" />
</div>
<div class="cleardiv" />
</asp:Panel>
<div class="centrebuttonsdiv" >
<asp:Label ID="lblTristanSearchInstructions" runat="server" Text="Select an appointment from the list above and click 'Save Section' to continue. Otherwise, click 'Clear Retrieved Information'
to search again" Visible="false" /><br />
<asp:Button ID="btnClearTristanSearch" runat="server" Text="Clear Retrieved Information" Visible="false" CssClass="largebutton" />
<asp:Button ID="btnSaveTristanLink" runat="server" Text="Save Section" OnClientClick="disablePanes()" Visible="false" Enabled="false" CssClass="largebutton" />
</div>
</Content>
</asp:AccordionPane>
I believe that changing this line:
<div class="cleardiv" />
to this
<div class="cleardiv"></div>
will solve that rendering problem; <div> is not typically a self-closing tag.
I want to do something very simple, only display an asp:image when I have value (i.e. not NULL) for the current DataItem.
As below, Image1 should only be output when there is a value for Image1 (i.e. Eval("Image1")) which is a field in the current DataItem.
<asp:PlaceHolder ID="NewsPlaceHolder" runat="server">
<asp:Repeater ID="NewsRepeater" runat="server">
<ItemTemplate>
<div class="newsItem">
<h3><%# Eval("Title") %></h3>
<div class="images">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# UrlHelper.NewsImageUrl((int)Eval("Id"),1) %>' />
<asp:Image ID="Image2" runat="server" ImageUrl='<%# UrlHelper.NewsImageUrl((int)Eval("Id"),2) %>' />
</div>
<div class="content"><%# Eval("Content") %></div>
</div>
<br class="clear" />
</ItemTemplate>
</asp:Repeater>
</asp:PlaceHolder>
Is there some simple conditional statements I can use in the ASPX page? Many thanks!
You can try to check if it is null from codebehind
<asp:Image ID="Image1" runat="server" visible='<%# HasData(Eval("image")) %>' ImageUrl='<%# UrlHelper.NewsImageUrl((int)Eval("Id"),1) %>'
C#
public bool HasData(object img)
{
if(img!=null) {return true;}
return false;
}
# aspx page.
<div class="images">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# UrlHelper.NewsImageUrl((int)Eval("Id"),1) %>' Visible = '<%#(Container.DataItem != null) ? true: false) %>' />
<asp:Image ID="Image1" runat="server" ImageUrl='<%# UrlHelper.NewsImageUrl((int)Eval("Id"),2) %>' Visible = '<%#(Container.DataItem != null) ? true: false) %>' />
</div>
If I have this:
<img ID="imgField" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"Name") %>' />
How can I add "images/" or any other string add on to the url?
I tried
ImageUrl=' "images/" + <%# DataBinder.Eval(Container.DataItem,"Name") %>'
And
ImageUrl= "images/" + '<%# DataBinder.Eval(Container.DataItem,"Name") %>'
And
ImageUrl='images/<%# DataBinder.Eval(Container.DataItem,"Name") %>'
But none of them worked. Anyone know?
<img ID="imgField" runat="server" ImageUrl='<%# string.Format("images/{0}", DataBinder.Eval(Container.DataItem,"Name")) %>' />
Or, if you want to shorten it up a bit...
<img ID="imgField" runat="server" ImageUrl='<%# string.Format("images/{0}", Eval("Name")) %>' />
and I think this should work too - but don't have a project in front of me to test it on...
<img ID="imgField" runat="server" ImageUrl='<%# Eval("Name", "images/{0}") %>' />
<img ID="imgField" runat="server"
ImageUrl='<%# "images/" + DataBinder.Eval(Container.DataItem,"Name") %>' />
Or inside a gridview, you could use an ImageField column:
<asp:GridView>
<Columns>
<asp:ImageField DataImageUrlField="Name"
DataImageUrlFormatString="images/{0}" />
</Columns>
</asp:GridView>
You were using
<%
instead of the correct:
<%#