Solved

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

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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