More in this section

Forums / Developing with Sitefinity / databound imageurl from image controle

databound imageurl from image controle

2 posts, 0 answered
  1. Philip
    Philip avatar
    8 posts
    Registered:
    16 Jun 2008
    16 Dec 2008
    Link to this post
    Hello,

    I have on my page an image controle and a custom control(for my special content).
    I there a way so that i can show a different image with different content.

    example:
    page.aspx?id=1
    content = 1
    ImageUrl = 1.jpg
    page.aspx?id=2
    content = 2
    ImageUrl = 2.jpg

    can i put this in my custom control:

    on pageload or databound image.umageurl = ...


    i'm hoping on a quick response,
    thank you,

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    16 Dec 2008
    Link to this post
    Hello Philip,

    I would recommend you wrap ASP.NET Image control in a user control and implement the required functionality in it. Here is a simple example:

    .ascx
    <asp:Literal ID="Literal1" runat="server"></asp:Literal> 
    <asp:Image ID="Image1" runat="server" /> 

    .ascx.cs
    protected void Page_Load(object sender, EventArgs e) 
        { 
            string id = Request.QueryString["id"]; 
     
            if (!string.IsNullOrEmpty(id)) 
            { 
                string url = "~/Images/" + id + ".jpg"
     
                this.Literal1.Text = id; 
     
                if (System.IO.File.Exists(Server.MapPath(url))) 
                { 
                    this.Image1.ImageUrl = url; 
                } 
            } 
        } 

    Finally, you should register the newly created control in <toolboxControls> section of the web.config to display it in Add Controls toolbox:

    <add name="ImageWrapper" section="Custom" url="~/UserControls/Custom/ImageWrapper.ascx" /> 

    Please describe in details if there is some misunderstanding.

    Kind regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered