Question

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.

Was it helpful?

Solution

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/>

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top