Solved

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

Posted on 2009-07-08
3
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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