Skip to content
June 29, 2009 / kiranpatils

Dynamically Loading Controls in a WebPartZone

Challenge:

I have configured my page to use WebPart — [Added WebpartManager,WebpartZone – Left,Center,Right]. Now, i show some list of items like Cricket Score, Current Weather….user can select one of them and when he/she says “OK”..I want to add my controls in WebpartZone..

Okay, leave this much complex i have one button on Webpart page on click of it i want to add one Calendar control to Webpartzone..How can i do this??

Solution:

you can do easily using following piece of code:

Calendar calendar = new Calendar();
GenericWebPart gwp = wpm.CreateWebPart(calendar); //wpm = Webpartmanager
//OR to get current webpartmanger use : 
WebPartManager.GetCurrentWebPartManager(Page) method
//Add Webpart
wpm.AddWebPart(gwp,wpzb,i); //webPart,WebpartZone,ZoneIndex

HTH🙂

Links:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager.addwebpart.aspx

Happy Programming!!:)

Calendar calendar = new Calendar();
GenericWebPart gwp = wpm.CreateWebPart(calendar); //wpm = Webpartmanager
//OR to get current webpartmanger use : 
WebPartManager.GetCurrentWebPartManager(Page) method
//Add Webpart
wpm.AddWebPart(gwp,wpzb,i); //webPart,WebpartZone,ZoneIndex

One Comment

Leave a Comment

Trackbacks

  1. asp.net, c#,javascript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: