Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now