Design and CSS styles
Version 7.x > Design and CSS styles > Regarding webpart container through custom code View modes: 
User avatar
Member
Member
sunil.gupta-aonhewitt - 7/22/2013 7:25:34 AM
   
Regarding webpart container through custom code
Hi,

We have created a web part container named 'Alert'.
I want to apply this webpart container to the staticText webpart but its not working.

<%@ Register Src="~/CMSWebParts/Text/statictext.ascx" TagName="StaticText" TagPrefix="cms" %>

<cms:StaticText runat="server" ID="alertBeneficiary" WordWrap="true" UseContainer="true" ContainerName="Alert"
Text="Beneficiay Text"/>

Plase suggest how can I apply the webpart container using custom code in a webpage.

Thanks
Sunil

User avatar
Member
Member
kentico_sandroj - 7/22/2013 3:17:38 PM
   
RE:Regarding webpart container through custom code
Hi Sunil,

Is the Web part container registered in the system? If so, could you please try applying it to a Web part in the UI? Please let me know if that works. There are also API examples available here.

Regards,
Sandro

User avatar
Member
Member
sunil.gupta-aonhewitt - 7/23/2013 5:32:18 AM
   
RE:Regarding webpart container through custom code
Hi Sandro,

Thanks for looking.

Yes, the webpart container registered in the system.
I tried it applyting it to a webpart using "UseContainer", "ContainerName" property but it does not work.

My requirement is very simple. I have created a webpart container named 'Alert' (registered).
I am using a webpart (StaticText) and trying to apply this container on the webpart
using following UI code but unfortunately not apply (this worked successfully if I assign the Web part container property with Alert using CMS Desk ).

[webpart code]
<cms:StaticText runat="server" ID="StaticText1" Text="" UseContainer="true" ContainerName="Alert"/>

or is there specific property using API. I tried this as well but this also did'nt worked.
WebPartContainerInfo alertContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("Alert");

StaticText1.Container = alertContainer;

User avatar
Member
Member
kentico_sandroj - 7/24/2013 2:16:43 PM
   
RE:Regarding webpart container through custom code
Hello,

Thank you for the additional clarification. Upon further investigation it became apparent that this approach would not work for setting the container without modifying the source code. The source code checks for an instance of a Web part, which is used by templates and doesn't exist in this case. Instead of using the container, you would have to manually set the content before and content after properties similar to the following:

<cms:MyStaticText runat="server" ID="az" ContainerName="OrangeBox" Text="sample" />

aZ.ContentBefore = aZ.ContainerBefore;
aZ.ContentAfter = aZ.ContainerAfter;

You would still specify a container name so that the properties are available. Please let me know if you have any questions.

Regards,
Sandro

User avatar
Member
Member
sunil.gupta-aonhewitt - 7/25/2013 5:34:33 AM
   
RE:Regarding webpart container through custom code
Hi Sandro,

This Worked. Great!
I would appreciate your quick and correct direction for resolving this issue.

Thanks
Sunil