Dear Users I am new in web parts I used webparts, webpartmanager,webpartzone at design time all are doing well now Sir how can I add WebPartZone dynamically in a table's TD(column) and webparts in that. Thanks Osman Ishaque
Here is an example that will add a WebpartZone into a TD and also add a GenericWebPart into the WebPartZone. The Zone's can't be added after the Page_Init event:
</div>
</form> NOTE: Before you add a WebPart, make sure it not already added to the Zone. When a WebPart is added, the
personalization feature of the WebPart feature will remember the added WebPart and the next time you visit the page, and when that happens, the code above will always add a new WebPart, so the next time there will be two WebParts on the page.
Dear well working code. But can we add WebPartZones against button click event every time we click button A new webpartzone will be added and store in DB against user.It is also working against button click but when I press button second time it not works.
Thanks Osman Ishaque
usmanishaque: WebPartZons can't be added after the Page_Init event. SO if you add a button and try to add a WebPartZone from the button click event, an exception will be thrown.
Sir I added WebPartZone on button click as I wrote code in Page init event code is void Page_Init(object sender, EventArgs e) { if (Request["var"]=="true") { WebPartZone zone1 = new WebPartZone(); zone1.ID = "osman"; zone1.Width = 100; zone1.Height = 100; zone1.EmptyZoneText
= "Empty"; MyZone.Controls.Add(zone1); Response.Write("dfa"); var="false"; } } On click event i send var=true; Now I want to add WebPartZone in DB I think that can be done by adding WebPartZone to WebPartZoneCollection. Can I do by WebPartZoneCollection? Thanks
Osman
The WebPartZone will not be saved into a data source (Only the WebParts will be saved by the personalization feature of the WebPart framework), you have to handle that by your own.
usmanishaque : If you don't add the WebPartZone in the Page_Init event or don't specify them on the page, they are basically removed because they don't exist. So to remove a WebPartZone, you simply do not add it to the page. > and change their positions like
Webparts? If you are talking about the way you can drag & drop WebParts, the answer is no. You can probably write your own functionality that can do that, but by default, you can't move around WebPartZones like you can move around WebParts. WebPartZones are
fixed zones on the page that is a container for WebParts, nothing more.
gurupak
Member
30 Points
6 Posts
Dynamically add remove WebPartZone
Sep 15, 2004 11:13 PM|LINK
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dynamically add remove WebPartZone
Sep 16, 2004 04:12 AM|LINK
<script runat="server"> public void Page_Init() { Button button = new Button(); button.ID = "testButton"; WebPart myWebPart = WebPartManager1.CreateWebPart(button); WebPartZone zone1 = new WebPartZone(); zone1.ID = "zone1"; MyZone.Controls.Add(zone1); WebPartManager1.AddWebPart(myWebPart, zone1, 0); } </script> <form id="form1" runat="server"> <div>MVP, ASPInsider, WCF RIA Services Insider
My Blog
Roger.Zhu
Member
110 Points
22 Posts
Re: Dynamically add remove WebPartZone
Sep 16, 2004 05:04 AM|LINK
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dynamically add remove WebPartZone
Sep 16, 2004 05:59 AM|LINK
<script runat="server"> public void Page_Init() { Button button = new Button(); button.ID = "testButton"; WebPart myWebPart = WebPartManager1.CreateWebPart(button); WebPartZone zone1 = new WebPartZone(); zone1.ID = "zone1"; MyZone.Controls.Add(zone1); WebPartManager1.AddWebPart(myWebPart, zone1, 0); } </script> <form id="form1" runat="server"> <div>MVP, ASPInsider, WCF RIA Services Insider
My Blog
usmanishaque
Member
60 Points
12 Posts
Re: Dynamically add remove WebPartZone
Sep 16, 2004 06:42 AM|LINK
usman@isf.com.pk
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dynamically add remove WebPartZone
Sep 16, 2004 07:18 AM|LINK
MVP, ASPInsider, WCF RIA Services Insider
My Blog
usmanishaque
Member
60 Points
12 Posts
Re: Dynamically add remove WebPartZone
Sep 16, 2004 07:48 AM|LINK
usman@isf.com.pk
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dynamically add remove WebPartZone
Sep 16, 2004 08:40 AM|LINK
MVP, ASPInsider, WCF RIA Services Insider
My Blog
usmanishaque
Member
60 Points
12 Posts
Re: Dynamically add remove WebPartZone
Sep 16, 2004 09:09 AM|LINK
usman@isf.com.pk
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Dynamically add remove WebPartZone
Sep 16, 2004 10:57 AM|LINK
MVP, ASPInsider, WCF RIA Services Insider
My Blog