SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a really simple question and probably hard answer.
i want to add webpartzone into my sharepoint page using c# code, how can i do that?
i search all of web and found nothing.
what i did is: i create visual web part project and added this code to page_init event of it:

protected void Page_Init(object sender, EventArgs e)
    WebPartZone webPartZone1 = new WebPartZone();
    webPartZone1.AllowLayoutChange = true;
    webPartZone1.EmptyZoneText = "No Data are provided";
    webPartZone1.Enabled = true;
    webPartZone1.HeaderText = "My Custom Zone";
    webPartZone1.Visible = true;


and it's doesn't work. but can give you some idea of what i want. im really confused. could anyone help. thanks anyway.

share|improve this question
This is a little old to still not have a definite answer ... – SpYk3HH Oct 11 '12 at 20:50
actually i give it up because it have some logical issue i think. as i said in Laurie's comments. – Jalali Shakib Oct 13 '12 at 20:38

Try adding your web part zone into the controls collection of a TD on your page instead of directly to the page. Also, make sure you give your new webpartzone an ID.

Your page markup:

    <td id="TopLeftZone" runat="server"></td>

Your code-behind:

WebPartZone webPartZone1 = new WebPartZone();
webPartZone1.ID = "myTopLeftZone";
. . .
share|improve this answer
thanks for replay. i try this but i got error, because how can i add the webpartzone with webpart. i think my solution is a mistake. – Jalali Shakib Jul 17 '11 at 13:38
Are you saying you got an error when you add your webpart to the page? And, do you mean you are going to solve your problem in another way? If you can add your webpartzone to the aspx page in the markup instead of using C#, that would certainly be a good solution. – Laurie Jul 17 '11 at 20:17
I'm saying that because when you wanna add your webpart in page you have to add to webpartzone that you selected in combobox and how can you add webpartzone in another one since webpart itself is in another webpartzone that selected?! but thanks for the time you spend. – Jalali Shakib Jul 19 '11 at 5:27

I think you will have to update the aspx file content directly (adding the webpart zone template tag).

Using the code you wrote, you won't persist the control addition

share|improve this answer

Your Answer


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.