Get EditableImage URL to set visibility from code behind

Manmath Kulkarni asked on February 9, 2017 09:58

Hi,

I have created web part using web user control .ascx. It contains grid of CMSEditableImages. I want to show/hide these images by add check for ImageUrl. I am trying following.

Control c = RecFindControl(this.Parent, Image1.ID.ToLower());
CMS.DocumentEngine.Web.UI.CMSEditableImage i= (CMS.DocumentEngine.Web.UI.CMSEditableImage)c;
System.Web.UI.WebControls.Image a = i.ImageControl;

But ImageControl always returns null. From ImageControl I want to get ImageUrl.

Using RecFindControl method provided here. https://devnet.kentico.com/articles/enhancing-the-findcontrol-method

Kindly help me into this.

Thanks in advance,
Manmath.

Recent Answers


Anton Grekhovodov answered on February 9, 2017 11:12

Hi Manmath,

You pass Image1.ID.ToString() to the method, so the method returns you Image1 control. If you already has link to Image1 you can use Image1.ImageUrl

Also, it looks like you have a wrong namespace CMS.DocumentEngine.Web.UI, try to use CMS.Controls

0 votesVote for this answer Mark as a Correct answer

Manmath Kulkarni answered on February 9, 2017 11:27

Hi Anton,

Thanks for your reply. As I am using Kentico 10, I need to use CMS.DocumentEngine.Web.UI instead of CMS.COntrols. Also I tried with Image1.ID.ToString(), but it still returns null ImageControl. So I am not able to use Image1.ImageUrl property.

Best regards,
Manmath.

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on February 9, 2017 13:54

Could you show your ascx markup?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.