How to render an embedded image at design-time?

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default How to render an embedded image at design-time?

    Hi,

    I have a custom web server control, specifically a composite control,
    that includes an image button. The image button takes an ImageUrl
    property that renders at _runtime_, but at design-time the image does
    not render unless the user chooses an image.

    I would like to display a default image at design-time (or _at_least_
    reduce the size of the "missing image" icon that Visual Studio
    displays--it is too big**[see footnote]**).

    The ImageUrl property can only point to a path, obviously, which means
    I must depend on the user to have an image at a certain path. Also, I
    cannot access the Request object (thus neither the
    Request.ApplicationPath) at design-time, so I can't even get a valid
    path at design-time anyways.

    Therefore, I would like to use an embedded resource (an image included
    in the Visual Studio project, with 'Build Action' marked as "Embedded
    Resource") at runtime.

    But from what I can tell, System.Web.UI.Design.ControlDesigner only
    allows me to really affect the HTML at design-time via
    GetDesignTimeHtml(). But I cannot display an embedded resource with
    HTML...

    Here are relevant parts of my code:

    ---------------------------------------------

    public class PopupCalendar : System.Web.UI.WebControls.WebControl,
    INamingContainer {
    private TextBox textBox;
    private Image image;

    ....

    protected override void CreateChildControls() {
    this.Controls.Clear();
    textBox = new TextBox();
    this.Controls.Add(textBox);
    textBox.ID = "TextBox";

    image = new Image();
    this.Controls.Add(image);
    image.ID = "Image";
    }

    ....

    }

    ---------------------------------------------

    public class PopupCalendarDesigner : WebDesign.ControlDesigner {
    public override string GetDesignTimeHtml () {
    PopupCalendar popcal = (PopupCalendar)this.Component;

    return "<input type=\"text\" style=\"width: " + popcal.Width + "px\"
    /><img style=\"width: 16px; height: 16px;\">";
    }
    }

    ---------------------------------------------

    **[footnote]**
    I have tried putting "image.Width = Unit.Pixel(16); image.Height =
    Unit.Pixel(16);" in CreateChildControls(), but that means that only
    16x16 images can be used, because this affects _both_ design-time and
    run-time.

    Thank you very much for your help!

    - Justin

    Justin M. Keyes Guest

  2. Similar Questions and Discussions

    1. Possible to render images embedded in RSS feed
      Some RSS feeds, such as those provided by CNN, actually render the <image> tag with a src equal to a file or URL on their server. I'm able to...
    2. Should Contribute editing render pages the same way asDreamweaver design mode?
      When editing pages in Contribute, should pages be rendered the same as they are in Dreamweaver Design Mode editing? I have a spry menu on my pages...
    3. custom control (with collection) do not render at Design time
      Hello, I built a custom control... Everithing is working fine... EXCEPT... ;-) When I first place the control on the webform at design time it...
    4. custom WebControl sometimes doesn't render at design time
      I've created quite a few WebControls with pretty good success. I've made designers, data-bound controls, and so on. (Thank you to Nikhil Kothari...
    5. Using Table control in a custom composite control. Control does not render properly in design time.
      All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control...
  3. #2

    Default RE: How to render an embedded image at design-time?

    Use the embedded resource to create a relative path to your image. The same
    way you would at runtime. Use the getdesigntimehtml method to display the
    path to your embedded image.

    Do you have the embedded image included in your solution directory? If so,
    then just point the getdesigntimehtml method to this file. If not, then use
    the above method.
    --
    Staff Consultant II
    Enterprise Web Services
    Cardinal Solutions Group

    Future Business Model
    Loan Origination Services
    National City Mortgage


    "Justin M. Keyes" wrote:
    > Hi,
    >
    > I have a custom web server control, specifically a composite control,
    > that includes an image button. The image button takes an ImageUrl
    > property that renders at _runtime_, but at design-time the image does
    > not render unless the user chooses an image.
    >
    > I would like to display a default image at design-time (or _at_least_
    > reduce the size of the "missing image" icon that Visual Studio
    > displays--it is too big**[see footnote]**).
    >
    > The ImageUrl property can only point to a path, obviously, which means
    > I must depend on the user to have an image at a certain path. Also, I
    > cannot access the Request object (thus neither the
    > Request.ApplicationPath) at design-time, so I can't even get a valid
    > path at design-time anyways.
    >
    > Therefore, I would like to use an embedded resource (an image included
    > in the Visual Studio project, with 'Build Action' marked as "Embedded
    > Resource") at runtime.
    >
    > But from what I can tell, System.Web.UI.Design.ControlDesigner only
    > allows me to really affect the HTML at design-time via
    > GetDesignTimeHtml(). But I cannot display an embedded resource with
    > HTML...
    >
    > Here are relevant parts of my code:
    >
    > ---------------------------------------------
    >
    > public class PopupCalendar : System.Web.UI.WebControls.WebControl,
    > INamingContainer {
    > private TextBox textBox;
    > private Image image;
    >
    > ....
    >
    > protected override void CreateChildControls() {
    > this.Controls.Clear();
    > textBox = new TextBox();
    > this.Controls.Add(textBox);
    > textBox.ID = "TextBox";
    >
    > image = new Image();
    > this.Controls.Add(image);
    > image.ID = "Image";
    > }
    >
    > ....
    >
    > }
    >
    > ---------------------------------------------
    >
    > public class PopupCalendarDesigner : WebDesign.ControlDesigner {
    > public override string GetDesignTimeHtml () {
    > PopupCalendar popcal = (PopupCalendar)this.Component;
    >
    > return "<input type=\"text\" style=\"width: " + popcal.Width + "px\"
    > /><img style=\"width: 16px; height: 16px;\">";
    > }
    > }
    >
    > ---------------------------------------------
    >
    > **[footnote]**
    > I have tried putting "image.Width = Unit.Pixel(16); image.Height =
    > Unit.Pixel(16);" in CreateChildControls(), but that means that only
    > 16x16 images can be used, because this affects _both_ design-time and
    > run-time.
    >
    > Thank you very much for your help!
    >
    > - Justin
    >
    >
    Michael Baltic Guest

  4. #3

    Default Re: How to render an embedded image at design-time?

    > Use the embedded resource to create a relative path to your image.

    How? Write it to the filesystem and reference the resulting path? I
    don't know of another way and this seems like a kludge.
    > Do you have the embedded image included in your solution directory?
    The image is embedded in the *webcontrol* assembly. Each project that
    wishes to use the webcontrol should not have to include the image in
    its own assembly/project/solution.

    Even if I did do that, I know no way of getting the project path at
    design-time (Request.ApplicationPath is not available at design-time).

    Thanks for your help.

    Justin

    Justin M. Keyes Guest

  5. #4

    Default Re: How to render an embedded image at design-time?

    I've never known a control to embed it's images into the assembly for a web
    control. You might want to do this to protect the code/resources from theft,
    but being the web, everything is downloaded to the user anyways.

    The Infragistics controls all have the associated images stored in the
    inetpub/wwwroot/aspnet_client/infragistics/ folders for each version/control.
    That way, you can change the images without having to recompile the control.

    This makes the control dependant on the images being deployed with to the
    server. The same thing happens when you are trying to deploy JavaScripts as
    well.

    If the images are independant of the dll, then you would be able to
    reference the aspnet_client folder for the image url.

    If they are tied to the dll, then you can stream the image to the designer.
    The same way you would stream an image during runtime.

    The point is really moot anyways. Design time html is never going to look
    the same as runtime html. The visual studio browser renders out html
    completely different than the latest version of IE, Mozilla, Firefox, etc.
    Also, if you have XP installed, then they will be way different!
    --
    Direct Email: [email]Michael.Baltic@RemoveCharactersUpTo#NCMC.Com[/email]

    Staff Consultant II
    Enterprise Web Services
    Cardinal Solutions Group


    "Justin M. Keyes" wrote:
    > > Use the embedded resource to create a relative path to your image.
    >
    > How? Write it to the filesystem and reference the resulting path? I
    > don't know of another way and this seems like a kludge.
    >
    > > Do you have the embedded image included in your solution directory?
    >
    > The image is embedded in the *webcontrol* assembly. Each project that
    > wishes to use the webcontrol should not have to include the image in
    > its own assembly/project/solution.
    >
    > Even if I did do that, I know no way of getting the project path at
    > design-time (Request.ApplicationPath is not available at design-time).
    >
    > Thanks for your help.
    >
    > Justin
    >
    >
    Michael Baltic Guest

  6. #5

    Default Re: How to render an embedded image at design-time?

    I'll deploy it as you recommend. Thanks for your direction.

    Justin

    Justin M. Keyes Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139