Microsoft Content Management Server - Image Placeholder Collection

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > November 2006 > Image Placeholder Collection





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Image Placeholder Collection
SPCMSDev

2006-11-27, 1:16 pm

Hi there,
I'm trying to check whether a single image placeholder control has an
image added to it and adding a css class to that placeholder if there
is an image. It works fine for one SingleImagePlaceholder control but
the issue is iterating through multiple SingleImagePlaceholder controls
in my template.

I'm iterating through the placeholders in a posting but I get an null
exception since my template also has other html placeholder controls.

Is there a way to get a collection of ImagePlaceholder controls only?
My code is as follows:

//iterate through placeholders
PlaceholderCollection phc =
CmsHttpContext.Current.Posting.Placeholders;
foreach(Placeholder ph in phc)
{
if(ph.GetType().ToString() ==
"Microsoft.ContentManagement.Publishing.Extensions.Placeholders.ImagePlaceholder")
{
//SingleImagePlaceholderControl singImgPH = ph as
SingleImagePlaceholderControl;
for(int i=1;i<=phc .Count-1;i++)
{
ImagePlaceholder[] imgPH = new ImagePlaceholder[phc .Count-2];
SingleImagePlaceholderControl[] SingImgPH = new
SingleImagePlaceholderControl[phc .Count-2];

imgPH[i] = (ImagePlaceholder)(SingImgPH [i].BoundPlaceholder);
SingImgPH [i].CssClass="thumbviewImg";

}
}
}

Any help is highly appreciated!

Thanks,
SPCMSDev

Stefan Goßner [MSFT]

2006-11-27, 1:16 pm

Hi,

first of all you should use

if (ph is ImagePlaceholder)

rather than

if(ph.GetType().ToString() ==
"Microsoft.ContentManagement.Publishing.Extensions.Placeholders.ImagePlaceholder")

In addition you are mixing up terms.
An ImagePlaceholder is not an ImagePlaceholderControl.

So you cannot cast placeholders to placeholder controls.

The placeholder control is the rendering engine on your ASPX template file
while the placeholder object represents the data in your database.

There is no way to get the placeholder control from the placeholder object
you can only do this the other way round.
You would need to search the controls in your control collection and check
the BoundPlaceholder property to get to the placeholder.

Cheers,
Stefan


"SPCMSDev" <seshupochampally@gmail.com> wrote in message
news:1164651648.611317.57410@f16g2000cwb.googlegroups.com...
> Hi there,
> I'm trying to check whether a single image placeholder control has an
> image added to it and adding a css class to that placeholder if there
> is an image. It works fine for one SingleImagePlaceholder control but
> the issue is iterating through multiple SingleImagePlaceholder controls
> in my template.
>
> I'm iterating through the placeholders in a posting but I get an null
> exception since my template also has other html placeholder controls.
>
> Is there a way to get a collection of ImagePlaceholder controls only?
> My code is as follows:
>
> //iterate through placeholders
> PlaceholderCollection phc =
> CmsHttpContext.Current.Posting.Placeholders;
> foreach(Placeholder ph in phc)
> {
> if(ph.GetType().ToString() ==
> "Microsoft.ContentManagement.Publishing.Extensions.Placeholders.ImagePlaceholder")
> {
> //SingleImagePlaceholderControl singImgPH = ph as
> SingleImagePlaceholderControl;
> for(int i=1;i<=phc .Count-1;i++)
> {
> ImagePlaceholder[] imgPH = new ImagePlaceholder[phc .Count-2];
> SingleImagePlaceholderControl[] SingImgPH = new
> SingleImagePlaceholderControl[phc .Count-2];
>
> imgPH[i] = (ImagePlaceholder)(SingImgPH [i].BoundPlaceholder);
> SingImgPH [i].CssClass="thumbviewImg";
>
> }
> }
> }
>
> Any help is highly appreciated!
>
> Thanks,
> SPCMSDev
>



SPCMSDev

2006-11-27, 7:19 pm

Stefan,

Your suggestion has worked.You are awesome!!

Thanks a lot!


Stefan Go=DFner [MSFT] wrote:
> Hi,
>
> first of all you should use
>
> if (ph is ImagePlaceholder)
>
> rather than
>
> if(ph.GetType().ToString() =3D=3D
> "Microsoft.ContentManagement.Publishing.Extensions.Placeholders.ImagePlac=

eholder")[vbcol=seagreen]
>
> In addition you are mixing up terms.
> An ImagePlaceholder is not an ImagePlaceholderControl.
>
> So you cannot cast placeholders to placeholder controls.
>
> The placeholder control is the rendering engine on your ASPX template file
> while the placeholder object represents the data in your database.
>
> There is no way to get the placeholder control from the placeholder object
> you can only do this the other way round.
> You would need to search the controls in your control collection and check
> the BoundPlaceholder property to get to the placeholder.
>
> Cheers,
> Stefan
>
>
> "SPCMSDev" <seshupochampally@gmail.com> wrote in message
> news:1164651648.611317.57410@f16g2000cwb.googlegroups.com...
aceholder")[vbcol=seagreen]

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com