Solved

ASP.net 3.5 - Programaticaly/Runtime: Add new WebZone from ServerSide Code

Posted on 2009-07-08
3
398 Views
Last Modified: 2013-11-26
ASP.net 3.5 - Web Application How To:
Programaticaly/Runtime: Add new WebZone from ServerSide Code
Need to dynamically create any number of webzones and associated webparts based on business objects saved in SESSION.
0
Comment
Question by:AEPUSER
3 Comments
 
LVL 15

Expert Comment

by:deepaknet
ID: 24812388
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 24823225
Hi,

I don't think the above article is what You are after. The concept of creating webparts / webzones from code behind is as follows:

1. You need to instantiate a WebPartManager either declaratively in your markup or in code behind:

Dim partManager As New WebParts.WebPartManager()
partManager.Personalization.Enabled = True
...

2. Put things in design mode:

Dim mode As WebParts.WebPartDisplayMode = partManager.SupportedDisplayModes("Design")
partManager.DisplayMode = mode
...

3. Add zones and parts according to some logic:

Dim numZones As Integer = CInt(Session("numWebZones"))
Dim numParts As Integer = CInt(Session("numWebParts"))
Dim i As Integer = 0
Dim j As Integer = 0

Do While i < numZones
    Dim zone As New WebParts.WebPartZone()
    zone.ID = "WebPartZone" & i.ToString()
    Do While j < numParts
        Dim literal As New LiteralControl("This is webpart " & j.ToString() & " in zone " & i.ToString() & ".")
        literal.ID = "WebPart" & i.ToString() & j.ToString()
        partManager.AddWebPart(partManager.CreateWebPart(literal), zone, j)
        j += 1
    Loop
    j = 0
    phZones.Controls.Add(zone)
    i += 1
Loop

4. Enjoy!

/Carl.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net mvc 2 35
How to set focus on a dynamic control 18 26
asp.net repeater 2 13
Need to find a web event on the IIS server 4 10
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question