1

I have created a visual web part that combines two other previously created web parts into one nicely styled web part. This is done simply by adding Register tags to the ascx page of the web part, and then adding the web part tags just as I would on a page layout, like so:

WebPart_ParentAssignmentsUserControl.ascx:

<%@ Register tagprefix="WebParts" namespace="Microsoft.SharePointLearningKit.WebParts" assembly="Microsoft.SharePointLearningKit, Version=1.3.1.0, Culture=neutral, PublicKeyToken=24e5ae139825747e" %>
<%@ Register tagprefix="MyChildrenWebPart" namespace="MLG2010.WebParts.MyChildren.MyChildrenWebPart" assembly="MLG2010.WebParts.MyChildren, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" %>

<WebParts:AssignmentListWebPart runat="server" ListScope="false" AllowEdit="True" AllowConnect="True" Title="Assignment List Web Part" IsIncluded="True" Dir="Default" SummaryWidth="150px" IsVisible="True" AllowMinimize="True" AllowHide="True" ExportControlledProperties="True" ZoneID="" ID="g_1c528b46_baf2_4cf2_a004_91f84c4f4556" FrameState="Normal" DisplaySummary="True" ExportMode="All" SuppressWebPartChrome="False" DetailLink="" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" AllowRemove="True" ToolTip="Assignment List - Use this web part to keep track of your SharePoint Learning Kit assignments." HelpMode="Modeless" FrameType="Default" AllowZoneChange="True" PartOrder="0" Description="Display the assignments for an instructor or learner." PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{1c528b46-baf2-4cf2-a004-91f84c4f4556}" WebPart="true" Height="" Width=""></WebParts:AssignmentListWebPart>
<MyChildrenWebPart:MyChildrenWebPart runat="server" PageSize="5" StudentsSiteURL="/student" PictureLibraryTitle="Students Picture Library" ADChildAttribute="otheripphone" Description="My WebPart" DefaultPictureURL="../../Students Picture Library/DefaultChild.jpg" ShowErrors="True" PictureLibraryUrl="../../Students Picture Library" Title="MyChildrenWebPart" ADEntryPoint="LDAP://dc=redconnect-test" __MarkupType="vsattributemarkup" __WebPartId="{d13a3729-e2b8-4436-ac1b-b75c914a3596}" WebPart="true" __designer:IsClosed="false" id="g_d13a3729_e2b8_4436_ac1b_b75c914a3596"></MyChildrenWebPart:MyChildrenWebPart>

The problem here, is that I need these two web parts to communicate via web part connections. since they are only added here on the aspx, sharepoint does not "know" about them, and thus they do not get a chrome and thus I cannot set up the web part connections in the browser.

Is there a way to set up web part connections on web parts that are added this way? Or maybe if I can just activate the chrome on these web parts?

3 Answers 3

0

I do not think this is a possible scenario, since the one who "owns" the connections - the web part zone, are not aware of these "sub" web parts.

You need to handle this communication in your own parent control.

And, why adding web parts to a web part. It's not the way Web Parts are intended to be used - they will just be regular controls in this scenario. The web part manager/framework will not see them and can not handle them.

1
  • i was adding them like this because doing otherwise (adding them straight to the web part zone) would have screwed up the branding, which would require valuable time and resources to fix. Any idea why my web part manager showed no web parts? it should at least show the parent web part shouldnt it?
    – Nacht
    Commented Jun 17, 2012 at 15:18
1

Interesting scenario :)
Have you considered programmatically connecting the web parts on load? You can do this in ascx's code behind or in the load of any one of teh webpart too

 using (SPLimitedWebPartManager spManager = webContext.GetFile(SPContext.Current.File.Url).GetLimitedWebPartManager(PersonalizationScope.Shared))
                {
                    WebPart consumer = spManager.WebParts.Cast().Where(w => w.GetType() == typeof(MyConsumerWebPart)).First();
                    WebPart provider = spManager.WebParts.Cast().Where(w => w.GetType() == typeof(MyProviderWebPart)).First();
                    var connections=  spManager.SPWebPartConnections.Cast().Where(c => c.Provider == provider && c.Consumer == consumer);

                    if (connections.Count() > 0)
                    {
                        //web parts are already connected
                        return;
                    }
                    else
                    {

                        ProviderConnectionPoint providerConnectionPoint = spManager.GetProviderConnectionPoints(provider)["MyConnectionProviderInterfaceId"];
                        ConsumerConnectionPoint consumerConnectionPoint = spManager.GetConsumerConnectionPoints(consumer)["MyConnectionConsumerInterfaceId"];
                        spManager.SPConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint);
                    }



                }
1
  • i have tried this, but the WebParts property of spmanager was empty. also i was getting the web parts by their ID, which may have been the problem. i will definitely try your way, thanks!
    – Nacht
    Commented Feb 28, 2012 at 20:33
0

This is the work around I normally use.

Add the two webparts to a pagelayout in SharePoint Designer, go to Design view, edit their properties and connection, then go to Code view and copy/paste the generated HTML into your ascx page in Visual Studio, and it should work.

Just remember to remove them again from the pagelayout.

2
  • hmm... this is a good idea, but I get "an unexpected error occurred while parsing this page." I'm going to try to create a page with the web parts added (not in designer) and then edit that.
    – Nacht
    Commented Feb 27, 2012 at 3:49
  • this method does not work for me. i believe the web parts' IDs are changed when they are loaded, thus making the consumerID and providerID not found.
    – Nacht
    Commented Feb 28, 2012 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.