Solved

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

Posted on 2009-07-08
3
396 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp day pilot 3 21
ASP.net 2015 Syncing Azure web app projects on two machines 2 21
Call Controller Action Method from ASPX 2 17
VB.NET 2008 - SQL Timeout 9 25
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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