Site structure
Version 5.x > Site structure > Determine if CMSEditableImage control has an image View modes: 
User avatar
Member
Member
jgriffith-nfusion - 11/14/2011 6:35:47 PM
   
Determine if CMSEditableImage control has an image
I am using aspx pages and trying to determine if a CMSEditableImage control has an image attached to it. If it doesn't I want to hide some elements on the page.

What is the best approach to this? I don't want to use javascript on the front-end but if there is not a good solution on the backend, I suppose I will have to resort to that.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/15/2011 5:18:56 AM
   
RE:Determine if CMSEditableImage control has an image
Hello,

You will have to go through the control hierarchy and use the FindControl method to get the correct control for displaying the image. Afterwards you should be able to access all it's properties, including the path.

Best regards,
Boris Pocatko

User avatar
Member
Member
jgriffith-nfusion - 11/15/2011 10:43:32 AM
   
RE:Determine if CMSEditableImage control has an image
Hi Boris,

Could you give me an explicit example of this? There is not much documentation on this so if you could post a concrete example that would be great.

Thanks,
Justin

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/16/2011 2:10:09 AM
   
RE:Determine if CMSEditableImage control has an image
Hello,

Regrettably, I am not able to post an explicit example because your controls hierarchy is different from mine. For example the following code could work to get the control:

this.Parent.FindControl("id");

or

this.Parent.Parent.FindControl("id");

...etc, it depends on the specific controls hierarchy build in your solution, which is build dynamically.

Best regards,
Boris Pocatko

User avatar
Member
Member
jgriffith-nfusion - 11/16/2011 9:34:41 AM
   
RE:Determine if CMSEditableImage control has an image
Sorry to keep asking questions but how would I get the path from this? It doesn't have to be "explicit" in that it will work in my project but just a complete example.

Thanks!

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/18/2011 2:58:52 AM
   
RE:Determine if CMSEditableImage control has an image
Hello,

I am not sure what example do you need. As I said, you need to get the control by the ID with the FindControl() method. If have obtained the control, you can use the line of code below to get the URL of the image:

string s = ((System.Web.UI.WebControls.Image)c.Controls[0]).ImageUrl;

Best regards,
Boris Pocatko