ASPX templates
Version 3.x > ASPX templates > Empty CMSEditableImage View modes: 
User avatar
Member
Member
inetmac510@yahoo.com - 8/7/2008 4:06:22 PM
   
Empty CMSEditableImage
How can I check in my template's code behind if a CMSEditableImage has had an image assigned to it or not?

The reason is that if no image is assigned it renders in the html like

<img id="blah" src="" style="border-width:0px;" />

The src="" causes Firefox to actually make another request back to the server to re-load the page, so if you're debugging this causes you to step through 2 times, or how ever many src="" there are on your page...

So to fix this I thought I'd just hide the editable image

Thanks!

User avatar
Member
Member
inetmac510 - 8/8/2008 8:55:24 AM
   
RE:Empty CMSEditableImage
I came up with a way to check this, I added an extension method for the CMSEditableImage class that takes the CurrentPage PageInfo object to check the value of the editable region, don't know if this is the best way or not, but here's the code.

public static bool IsPopulated(this CMSEditableImage editableImage, PageInfo currentPage)
{
bool isPopulated = false;

string value = currentPage.EditableItems.EditableRegions[editableImage.ID.ToLower()].ToString();

if (!string.IsNullOrEmpty(value))
{
value = value.ToUpper();
isPopulated = (value == "<IMAGE><PROPERTY NAME=\"IMAGEPATH\"></PROPERTY></IMAGE>") ? false : true;
}

return isPopulated;
}