0

I know this is a dumb question. For some reason my mind is blank on this. Any ideas?

Sorry should have been more clear.

Using a HtmlGenericControl to pull in link description as well as image.

 private void InternalCreateChildControls()
    {
        if (this.DataItem != null && this.Relationships.Count > 0)
        {
            HtmlGenericControl fieldset = new HtmlGenericControl("fieldset");
            this.Controls.Add(fieldset);
            HtmlGenericControl legend = new HtmlGenericControl("legend");
            legend.InnerText = this.Caption;
            fieldset.Controls.Add(legend);

            HtmlGenericControl listControl = new HtmlGenericControl("ul");
            fieldset.Controls.Add(listControl);

            for (int i = 0; i < this.Relationships.Count; i++)
            {
                CatalogRelationshipsDataSet.CatalogRelationship relationship =
                    this.Relationships[i];

                HtmlGenericControl listItem = new HtmlGenericControl("li");
                listControl.Controls.Add(listItem);

                RelatedItemsContainer container = new RelatedItemsContainer(relationship);
                listItem.Controls.Add(container);

                Image Image = new Image();
                Image.ImageUrl = relationship.DisplayName;




                LinkButton link = new LinkButton();
                link.Text = relationship.DisplayName;



               ///ToDO Add Image or Image and description
                link.CommandName = "Redirect";
                container.Controls.Add(link);
            }
        }
    }

Not asking anyone to do this for me just a reference or an idea.

Thanks -overly frustrated and feeling humbled.

1
  • could you elaborate? What are you meaning by dynamic in this situation? like created on the fly? and by url? I've done things with header images that change base on the URL typed in a CMS system.. is this what you are referring to? Commented Sep 22, 2008 at 19:18

3 Answers 3

2

I'm assuming you want to generate an image dynamicly based upon an url.

What I typically do is a create a very lightweight HTTPHandler to serve the images:

using System;
using System.Web;

namespace Example
{  
    public class GetImage : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString("id") != null)
            {
                // Code that uses System.Drawing to construct the image
                // ...
                context.Response.ContentType = "image/pjpeg";
                context.Response.BinaryWrite(Image);
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

You can reference this directly in your img tag:

<img src="GetImage.ashx?id=111"/>

Or, you could even create a server control that does it for you:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Example.WebControl
{

    [ToolboxData("<{0}:DynamicImageCreator runat=server></{0}:DynamicImageCreator>")]
    public class DynamicImageCreator : Control
    {

        public int Id
        {
            get
            {
                if (ViewState["Id" + this.ID] == null)
                    return 0;
                else
                    return ViewState["Id"];
            }
            set
            {
                ViewState["Id" + this.ID] = value;
            }
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write("<img src='getImage.ashx?id=" + this.Id + "'/>");
            base.RenderContents(output);
        }
    }
}

This could be used like

<cc:DDynamicImageCreator id="db1" Id="123" runat="server/>
Sign up to request clarification or add additional context in comments.

1 Comment

I have used this technique several times (e.g. proxy uploaded images), and it has worked well.
0

Check out the new DynamicImage control released in CodePlex by the ASP.NET team.

Comments

-1

This is kind of a horrible question. I mean, .NET has an image control where you can set the source to anything you want. I'm not sure what you're wanting to be discussed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.