The ConnectWebParts method cannot be called after connections have already been activated (in WebPar

R

ryan.mclean

Hi all, I am dynamically making the connection between two webparts
when the consumer is added like so:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
Dim wpGif, wpGroupSelector As WebParts.WebPart

Dim objWpManager As WebParts.WebPartManager =
CType(Page.Master.FindControl("wpmMain"), WebParts.WebPartManager)

Dim objPartCollection As WebParts.WebPartCollection =
objWpManager.WebParts
Dim objPart As WebParts.WebPart

Dim cpGroupSelector As WebParts.ProviderConnectionPoint
Dim cpGif As WebParts.ConsumerConnectionPoint

If ((Page.IsPostBack _
AndAlso (Request.Form("__EVENTARGUMENT") = "add" _
And Request.Form("__EVENTTARGET").IndexOf("czMain")
Or Not Page.IsPostBack) _
) Then

For Each objPart In objPartCollection
If (objPart.AllowConnect) Then
If (objPart.Title = "Group Selector") Then
wpGroupSelector = objPart
ElseIf (objPart.Title = "GIFs") Then
wpGif = objPart
End If
End If
Next

If (Not IsNothing(wpGroupSelector)) Then
cpGroupSelector =
objWpManager.GetProviderConnectionPoints(wpGroupSelector)(0)
End If

If (Not IsNothing(wpGif)) Then
cpGif =
objWpManager.GetConsumerConnectionPoints(wpGif)(0)
End If

If (Not IsNothing(cpGroupSelector) And Not IsNothing(wpGif)
_
AndAlso
objWpManager.CanConnectWebParts(wpGroupSelector, cpGroupSelector,
wpGif, cpGif)) Then
objWpManager.ConnectWebParts(wpGroupSelector,
cpGroupSelector, wpGif, cpGif)
End If

End If
End Sub

I know I am not showing all the code, but from what I have listed, can
anyone help me out. What is the deal? In the page_init the controls
don't exist, and in the page_prerender it's too late to connect them. I
am so close

Thank you for any help you can offer,
Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top