Determine URL of an ImagePlaceholder

I came across a problem recently whereby I wanted to determine the MCMS URL of an image stored in the MCMS Resource gallery.  The script had several image placeholders, some of which may of had images bound to them.

My requirements involved determining the URL of any given image and then to use this in some CSS styling.   Faced with this scenario the following code should help:

//Setup placeholder object and string for URL
Placeholder pl;
string imgSrcUrl = "";

//setup default CSS string
string FeatureCSS = ””;

pl = ImageX.BoundPlaceholder;//get the bound placeholder for this control
if (pl!=null){//test the placholder is not null
imgSrcUrl = ((ImagePlaceholder)pl).Src ;//get the source url from the placholder
if (imgSrcUrl!=null && imgSrcUrl!=”"){
FeatureCSS = “<style type=\”text/css\”>\n#section {\nheight: 232px;\nbackground: url(”+imgSrcUrl+”) no-repeat -26px 0;\n}\n</style>”;
else doSomethingElse();
else doSomethingElse();

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.