Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I Have a webpart page, which has layout as shown in picture,

WebPart Page Layout

Now I want to add a webpart to second "Top" zone of my page but I dont know how to access it, If I want to add it to first top zone I use this code,

WPMgr = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared);
WebPart CmsWP = new WebPart();
this.WPMgr.AddWebPart(CmsWP, "Top", 0);

Cheers

share|improve this question
    
Hi you can check this link it may help you sharepoint.stackexchange.com/questions/9442/… –  Vishal_Sharepoint Apr 23 '12 at 13:32
    
Hi, Nope this link didn't helped at all :| ? –  Muhammad Raja Apr 23 '12 at 13:34
2  
You should not use the same name for different zones. –  marco Apr 23 '12 at 13:54
    
I am working on some big project made by someone, and there's many webparts and synchronized operations are happening, changing Name will simply gonna break numbers of other things :( –  Muhammad Raja Apr 23 '12 at 13:59
add comment

1 Answer

up vote 2 down vote accepted

If your page has 2 zones with the same ID you're not going to stand much chance. Check what ID the second zone has, though - web part zones are controls and you can't have two web controls with the same ID.

Note that the text 'Top' is not necessarily the same as the ID. Look at the zone's definition through something like SharePoint Designer:

<WebPartPages:WebPartZone runat="server" Title="Left" ID="CenterLeftColumn"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>

This would display the heading of 'Left', but you'd need to refer to the zone with 'CenterLeftColumn'

share|improve this answer
    
True, but can I add a webpart to a zone using its ID, not name as atm I think am using its name, if am not wrong. Cheers –  Muhammad Raja Apr 24 '12 at 11:53
1  
At the moment, you're using 'Top' which is probably the ID of one web part zone, and the title of Two zones. You'd need to find out the ID of the second 'top' zone. The API documentation says that AddWebPart() uses the ID of the web part zone. –  Andy Burns Apr 25 '12 at 15:18
    
I solved the problem by adding webpart manually and saving it as a template, but just for knowledge if you can us how to find ID of a page please :) –  Muhammad Raja Apr 26 '12 at 7:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.