ASPX templates
Version 5.x > ASPX templates > using CMSDocumentValue control for image fields? View modes: 
User avatar
Member
Member
henry - 1/13/2010 8:01:54 PM
   
using CMSDocumentValue control for image fields?
Hi guys, I have an aspx page template for a document type which has a number of fields, including plain text, HTML and image types. On my aspx template, using CMSDocumentValue works perfectly for the text and html regions, but CMSDocumentValue just returns the attachment GUID for the image, instead of giving me the image itself, or the src of the image.

I thought about making a transformation for the document type and using CMSViewer but I'm not sure if this is the best solution - does anyone have any better ideas on what control to use or how I can display an image field from a document type on a page template?

User avatar
Member
Member
henry - 1/13/2010 8:24:36 PM
   
RE:using CMSDocumentValue control for image fields?
I've managed to do this by doing:

<img src="http://mysite/CMSPages/GetFile.aspx?guid=<%Response.Write(CMSContext.CurrentDocument.GetValue("SectionImage")); %>" />


If anyone has a cleaner way (preferably one that doesn't involve inline code), please let me know! :)

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 1/15/2010 5:38:33 AM
   
RE:using CMSDocumentValue control for image fields?
Hi Henry,

Alternatively, you can use asp:Image control and set its ImageUrl property using similar code in code-behind.

Best Regards,

Martin Dobsicek


User avatar
Member
Member
cshanks-tmw - 4/8/2010 11:29:38 AM
   
RE:using CMSDocumentValue control for image fields?
Hi Henry / kentico_martind - did you get this working?

We are having the worst trouble getting the images to display :(

.aspx
<asp:Image runat="server" ID="ImageTest" AlternateText="" ToolTip="" />

.aspx.cs

ImageTest.ImageUrl = "~/CMSPages/GetFile.aspx?nodeguid=" + CMSContext.CurrentDocument.GetValue("RecipeMainImage");

This does not work for us at all - can you give me any pointers?

User avatar
Member
Member
henry - 4/8/2010 3:49:12 PM
   
RE:using CMSDocumentValue control for image fields?
Try using "~/CMSPages/GetFile.aspx?guid=" instead for the ImageUrl? Otherwise it looks the same as I eventually got it working.

User avatar
Member
Member
cshanks-tmw - 4/9/2010 3:09:11 AM
   
RE:using CMSDocumentValue control for image fields?
Thanks for replying Henry!

We ended up using in the aspx page template:

<asp:Image runat="server" ID="ImageTest" CssClass="" />


in the .cs file:

ImageTest.ImageUrl = "~/CMSPages/GetFile.aspx?nodeguid=" + CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("ImageURL");

ImageTest.AlternateText = CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("ImageTitle").ToString();

ImageTest.ToolTip = CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("ImageTitle").ToString();

to access the document type form properties!

Thanks :)
Cass