Page view counter

asp:image question

Last post 05-29-2007 2:28 AM by raheel.hussain. 3 replies.

Sort Posts:

  • asp:image question

    05-28-2007, 3:11 AM
    • Loading...
    • Goldfish
    • Joined on 01-10-2006, 7:54 PM
    • Posts 15
    • Points 18

    Can anyone please tell me why the following won't work
    <asp:Image ID="id_image" runat="server" ImageUrl="<%= Page.Theme.ToString() %>/images/icon/icon_tack.gif" /> (server control)

    but it works for
    <img src="/App_Themes/<%= Page.Theme.ToString() %>/images/icon/icon_tack.gif" alt="" /> (not a server contorl)

    Thanks

    Filed under:
  • Re: asp:image question

    05-28-2007, 5:46 AM
    • Loading...
    • raheel.hussain
    • Joined on 05-24-2006, 4:00 AM
    • Dubai, UAE
    • Posts 225
    • Points 1,110


    following both should work, but rather in the server control, you can just simply specify as below
    where the sign of " ~ "  denotes the site home and will return the URL of your application.

    the reason is that since runat=server makes the control processed/randered on the server side and <%=%> signs are considered as literals and ignored  

    <asp:Image ID="id_image" runat="server" ImageUrl="~/App_Themes/TestTheme/images/icon/icon_track.gif" /> (server control)
    <
    img src="App_Themes/<%= Page.Theme.ToString() %>/images/icon/icon_track.gif" alt="" /> (not a server contorl)

    While TestTheme is the page theme which is hard coded.

    As far as I know, if you do not require any further processing over the image, keep it as HTML control

    otherwise you need to programmatically control the image URL, in the page load or may be some other event.

    Image1.ImageUrl = "~/App_Themes/" + Page.Theme + "/images/icon/icon_track.gif";

    regards
    raheel

    Raheel Hussain
    --------------------------------
    Blog:
    http://www.dnfug.com/web/blogs/raheel/

    URL: http://www.raheelhussain.com/
    --------------------------------

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: asp:image question

    05-28-2007, 2:01 PM
    • Loading...
    • Goldfish
    • Joined on 01-10-2006, 7:54 PM
    • Posts 15
    • Points 18
    Thanks for your reply raheel.

    But I find that
    <img src="App_Themes/<%= Page.Theme.ToString() %>/images/icon/icon_track.gif" alt="" /> only works in a Template of a Datalist

    If I have a simple page like:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Theme="default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <body>

    <form id="form1" runat="server">

    <div>
         <img src="App_Themes/<%= Page.Theme.ToString() %>/images/icon/icon_track.gif" alt="" />
    </div>

     </form>
    </body>

    </html>

    I will get an error saying "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)".  Anyone knows why this happens?

    Thanks

  • Re: asp:image question

    05-29-2007, 2:28 AM
    Answer
    • Loading...
    • raheel.hussain
    • Joined on 05-24-2006, 4:00 AM
    • Dubai, UAE
    • Posts 225
    • Points 1,110

    hi

    May be the following link would help you out.

     http://west-wind.com/weblog/posts/5758.aspx

    regards 

     

    Raheel Hussain
    --------------------------------
    Blog:
    http://www.dnfug.com/web/blogs/raheel/

    URL: http://www.raheelhussain.com/
    --------------------------------

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (4 items)