Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > image selector in widget. View modes: 
User avatar
Member
Member
gatsby0121 - 3/1/2012 1:33:15 AM
   
image selector in widget.
If I add an image selector field in a webpart (turned into a widget), how can I display the image that's saved in the widget from the code behind?

So when you add the widget to the page, and in the properties you select an image stored in the database, what do I need to do in the codebehind to display that image on the page?

User avatar
Member
Member
kentico_michal - 3/1/2012 6:00:32 AM
   
RE:image selector in widget.
Hello,

You need to add a new property that would represent the Image selection field to the code bind. Assuming that the field added to the webpart is called Image, you can use the folling code:
    public string Image
{
get
{
return ValidationHelper.GetString(this.GetValue("Image"), "");
}
set
{
this.SetValue("Image", value);
}
}

The Image selection form control stores the NodeGUID, so you can use the
TransformationHelper.HelperObject.GetDocumentUrl method to get Url of the image and as soon as you have this Url, you can display it where you need (for example, using the asp:Image control):

string imageUrl = TransformationHelper.HelperObject.GetDocumentUrl(Image, "Image");

Best regards,
Michal Legen