473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Programmatic adding of WebParts

How is a WebPart programmatically added to a WebPartZone, in code-behind?

I would intuitively think that something like this is the way to go:

this.WebPartManager1.Zones["WebPartZone1"].Controls.Add(myPart);

but of course that does not work (WebPartZone does not allow child control),
presumably since the location of the WebParts within the zones etc. are
determined dynamically by the framework, even if the html source places a
specific control in a specific Zone.

So, I want to add a WebPart control to a specific WebPartZone runtime, e.g.
in Page_Load for the page (without having to define the control in the .aspx
design time).

I have played around with various Controls collections, but either they do
not work, or the control is added at the very end of the page, after the
form and body tags :-(

Anyone?
-Paal
Nov 19 '05 #1
2 1029
And just to make it clear, this relates to ASP.NET 2.0, not Sharepoint :-)

-Paal
Nov 19 '05 #2
Found it, this does the trick:

this.WebPartManager1.AddWebPart(myPart,
WebPartManager1.Zones["WebPartZone1"], 0);
:-)

-Paal
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Barbara Alderton | last post by:
I am working with SharePoint 2003. I am using (using C#) an existing webpart as a child control (server control). I need to access/manipulate the HTML that the control outputs prior to rendering...
1
by: Astera | last post by:
I seem to be having a problem using web parts after the beta 2 release. Any time I try to have the WebPartManager on any page, I get the exception listed below. I've gone through the steps listed...
4
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set...
3
by: Bart Van Hemelen | last post by:
I'm working on a project where the user of a site will receive custom content, depending on a set of parameters. The content will all be contained in UserControls (.ascx), that will be used as...
6
by: brianroisentul | last post by:
Hello, I'd like to know which dll I have to reference when I use the System.Web.UI.WebControls.Webparts namespace. Thanks, Brian
3
by: Q. John Chen | last post by:
I have an INTRAnet site that need to add some content management feature. And I thought that I can use the WebParts. Since this is an internal site, I use Windows authentication so the use don't...
0
by: Ryan | last post by:
Hi everyone, I have enabled my webparts site to use ajax by simply using updatepanels. This worked fine. Now I tried to enable drag and drop for the webparts so I added some stuff to the web...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
3
by: clintonG | last post by:
Why don't we see more WebParts being used on the web? SharePoint gets all the fun? And what are the prevailing opinions be they what they may about the use of WebParts rather than WPF when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.