3

I am installing a web part on a few different pages. I have set my zone index to 0, yet they still wind up below the other web parts on the page. Here is my code:

        TasksWebPart intakeTasksWebPart = new WebPart();
        intakeTasksWebPart.Title = "Tasks Web Part";
        intakeTasksWebPart.ChromeState = System.Web.UI.WebControls.WebParts.PartChromeState.Normal;
        intakeTasksWebPart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleAndBorder;
        webPartManager.AddWebPart(intakeTasksWebPart, "Full Page", 0);
        web.Update();

There are no other web part zones that I can see on the page other then Full Page. There is already a web part on the page before my code tries to add this web part. When I open the page, my web part will be at the bottom and have a zone index of 2 or 3.

Any thoughts?

1
  • Is this using SPLimitedWebPatManager, by any chance?
    – James Love
    Jul 21, 2012 at 7:23

1 Answer 1

4

Make sure you're using the ID of the zone (which usually doesn't contain space) and not the Display title which is shown in the UI.

If you specify a non existing ID SharePoint may add your web part to the last zone on the page, but doesn't care about the Index

If you search view source of the page in edit mode (with web part zone showing) for zoneTitle="Full Page" you find a table the zoneID attribute is what you want.

4
  • I remember correctly specifying a non-existing zone name adds it to that zone anyways (thus storing it in a zone, that does not exist on the page). Had that issue a cpl of years back and we needed to add that "invisible" zone to the page so we could remove all the failed WPs. Jul 21, 2012 at 8:41
  • @Meyer Denney: You can find out the ID of the Zones in the pages by going to "Edit WebPart" section of any of the existing webparts on the page and looking in the "Layout" Section. Jul 21, 2012 at 18:26
  • Yes I went into the Layout section of Edit Web Part. The section was called "Full Page" and the zone index for the web part I installed was 3, sometimes 4, but in the code I have it set as 0. Jul 21, 2012 at 23:37
  • 1
    Beware what you see in the Layout section is the Title of the WebPartZone and you need the ID. If you have the "Edit Web Part" open you can use IE Developer Tools (or view source) to see what is the value attribute of the <option> tag with content "Full Page". If you search view source of the page in edit mode (with web part zone showing) for zoneTitle="Full Page" you find a table the zoneID attribute is what you want. Jul 22, 2012 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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