CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
Explore    Item Entry    Members   
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.web_parts_and_personalization Tags:
Item Type: NewsGroup Date Entered: 8/30/2006 7:20:59 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 5 Views: 12 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
6 Items, 1 Pages 1 |< << Go >> >|
toddhd
Asp.Net User
Enumerating all the web parts on a page - from a web part8/30/2006 7:20:59 PM

0/0

I have a web part that needs to examine every other web part on a given page for info. I've tried two approaches, but neither seems to be the answer I'm looking for.

First, I tried getting a reference to Parent (which returns the WebPartManager) and enumerating through it's Controls (or WebParts) collection. This almost works - it gives me every web part in the same WebPartZone as my web part. But it doesn't give me all the web parts in the other zones. Example:

            WebPartManager wpm = (WebPartManager)this.Parent;
            foreach (WebPart wp in wpm.WebParts)
            {
                Debug.WriteLine("I found " + wp.Title);
            }

After some thinking I decided to try and enumerate through the Zones as well, but that yielded the same results. It only gives me the Zone I'm in for some reason. I don't understand why.

            WebPartManager wpm = (WebPartManager)Parent;
            foreach (WebPartZone wpz in wpm.Zones)
            {
                Debug.WriteLine("In Zone " + wpz.ID);
                foreach (WebPart wp in wpz.WebParts)
                {
                    Debug.WriteLine("I found " + wp.Title);
                }
            }

My second thought was to simply grab all the controls on the Page, and loop through them looking for web parts. There are two problems with this. First, we use a Site.Master as well as web parts, so the only control in the Page.Controls collection is Site.Master. Second, I want my web part to function in any given web page, so I don't want to hard-code something to work around my particular layout. So enumerating the Page controls is out.

Can anyone clue me in as to how I can enumerate all Web Parts in all zones - from a web part?


-Todd Davis
http://www.SeaburyDesign.com
davidbarkol
Asp.Net User
Re: Enumerating all the web parts on a page - from a web part8/30/2006 10:08:07 PM

0/0

You can get a reference to the collection of webparts on the page be accessing WebParts property of the WebPartManager:

 WebPartCollection parts = WebPartManager1.WebParts;


David Barkol | ASP.NET AJAX in Action
toddhd
Asp.Net User
Re: Enumerating all the web parts on a page - from a web part8/31/2006 12:01:59 AM

0/0

But look at the first line of both my examples - that's exactly what I'm doing.

The thing is, this works fine if I access the WebPartManager from the Page's code-behind. It returns all the web parts.

But I need to reference the WebPartManager from the Webpart. When you access the Parent of a web part, it returns a reference to the WebPartManager it resides in. But for some reason, the WPM only seems to recognize the zone from the calling web part. Try it, you'll see. Something like this:

public MyClass : WebPart

{

public void SomeFunction()

{

          WebPartManager wpm = (WebPartManager)this.Parent;
            foreach (WebPart wp in wpm.WebParts)
            {
                Debug.WriteLine("I found " + wp.Title);
            }

}

}


-Todd Davis
http://www.SeaburyDesign.com
toddhd
Asp.Net User
Re: Enumerating all the web parts on a page - from a web part8/31/2006 1:03:10 AM

0/0

Never mind, I just setup a small test project outside of my main project, and the code posted above works just fine in the test. My main project uses MS Atlas, and I wonder if maybe that has something to do with what I'm seeing? Anyway, it works fine in my test project, so I'll have to look for what's different now.
-Todd Davis
http://www.SeaburyDesign.com
davidbarkol
Asp.Net User
Re: Enumerating all the web parts on a page - from a web part8/31/2006 1:09:34 AM

0/0

Oops, sorry about that. I should have read your post more carefully. Try this:

        WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);
        foreach (WebPart wp in wpm.WebParts)
        {
            System.Diagnostics.Debug.WriteLine("Found {0}", wp.Title);
        }

David Barkol | ASP.NET AJAX in Action
toddhd
Asp.Net User
Re: Enumerating all the web parts on a page - from a web part8/31/2006 1:33:06 AM

0/0

Thanks - I've never seen the GetCurrentWebPartManager call before - I was really hoping that would do it, but the results were the same. I removed the Atlas Update Panel as well, and was hoping that might be the problem (Atlas does all kinds of funny things to web parts) but that didn't help either. I'm so confused. Clearly the syntax is correct, so I'm not sure why the results are being limited to a single zone. We have two zones on the page, with the ability to add more dynamically, but those initial two are "hard coded" into the HTML, so they should show up.
-Todd Davis
http://www.SeaburyDesign.com
6 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

Cancel Button on Web Part Editor Zone - ng.asp-net-forum ... smtp from membership part of app. external pages with master pages "cancel" login? ... web parts, custom gadgets, editor zone, web configuration file, other ...
PersonalizationScope Enumeration (System.Web.UI.WebControls.WebParts) Indicates the personalization scope for a WebPartManager object or the personalization scope that applies to a property on a Web Parts control.
WebPartPagesWebService Class (Web Part Pages) Provides methods for working with Web Parts. ... Web Part Pages Web Service. FormatConversionOption Enumeration. SPWebServiceBehavior Enumeration ...
Australian Aboriginal enumeration - Wikipedia, the free encyclopedia ... in the following tables, names for numbers were based on body parts, whose names ... that part of the just above. and behind the ear. 13. Doke doke. from ...
What's new in J2SE 5.0? Part 3: MetaData / Annotations and Enumerated ... ... Articles and Interviews about the latest in Java software ... Page 1 of 4. In the first two parts of this series of articles, we had a look at generics, ...
Computerized Isomer Enumeration of the Alkane Series Page 1 the acyclic generator was used to attach branched structures to the produced cyclic parts. ... long chains of a diameter from the carbon content to a diameter ...
Sharing Points { }: SharePoint Web Part Template ... will create a calendar web part that could be displayed in the home page of our ... a specific Web Part zone, click Add a Web Part to the Add Web Parts ...
Use the Power of Reflection to Dynamically Set SharePoint Web Part ... ... your collection of Web parts, you need to identify your Page Viewer Web part. ... GetProperties() takes a bitwise enumerated value for flags that control binding. ...
Cancel Button on Web Part Editor Zone - ng.asp-net-forum ... smtp from membership part of app. external pages with master pages "cancel" login? ... web parts, custom gadgets, editor zone, web configuration file, other ...
To print update pages, click on A Print @ BACK ... or assessments, in whole or in part thereof, shall become due and ... corridors, entrances and other parts of the buildings belonging ... enumerated ...
Microsoft Windows 2000 Scripting Guide - Enumerating Files and File ... In the NTFS file system, files are actually made up of two distinct parts. ... Top of page. Manage Your Profile |Contact Us |Newsletter © 2008 Microsoft Corporation. ...


 
All Times Are GMT