IwebpartRow - connect a customized webpart with existing list webpart - Page object not available in the GetRowData method.
-
Sunday, July 04, 2010 3:07 AM
Hello,
Here is the case where I am seeking help.
Client had requested a custom web part with : (1) Ability to choose List (2) Ability to choose view of the selected list (3) Ability to decide number of dynamic search fields to be displayed on the page (e.g. 5 )
Above three things are configured in the Configuration section (right pane). Once clicked on Apply and ok, web part will dynamically add 5 Dropdownlist (populated with column names of selected view of the selected list) and 5 textboxes where user can provide value. Once columns are choosen from dropdown and values to search are provided in textboxes, user clicks on the Search Button.
As soon as user clicks on the search button - a dynamic CAML is generated and a listviewbyquery control is rendered with filtered values.
*********I HAVE ACHIEVED THE FUNCATIONALITY SO FAR*********
Now, client wishes to have this web part an ability to connect to other webparts. After reading an example from MSDN - I started implementing IWebPartRow and soon figured out that when GetRowData function is called at runtime from another webpart - the functionality breaks. While debugging - I figured out that this.Page object is not available and hence all the dynamic controls (5 dropdownlist and 5 textboxes) I have created so far are not available.
Please note that ListViewByQuery is populated based on the dynamic search fields and hence each time page loads all the controls need to be loaded !
At this point - I don't have any clue how to move ahead. I am almost sure that the issue is because of the above mentioned reason only. But not too sure - if I am missing on any minute detail !
If this doesn't make it much clear, please let me know your email address and I can send the code along with screenshot of the webpart for your reference. PS: Code is very big and hence won't make sense to post along with this question.
Thanks,
Whizsid
- Edited by whizsid Wednesday, July 07, 2010 1:20 PM
All Replies
-
Tuesday, July 06, 2010 8:48 AMModerator
Hi Whiz,
From the points you have draw down, it seems that the GetRowData function [in the Consumer webpart] is called before the Page Load event of the 1st Webpart [Row Provider]. Can we cross check by debugging the webpart code?
AnjaliCH-MSFT -
Wednesday, July 07, 2010 1:19 PM
Anjali,
You are correct. While debugging, I did check that for many times and that is exactly what has been happening.
What should be the next step ?
Tried following approach but yet not successful. (Just to get your opinion)
In the code, with reflection, I checked the private members of consumer webpart and one member is _provider of type (IWebPartRow). I thought of assigning that member with 1st webpart object value (i.e. this) soon after Onload event of (provider webpart) is fired.
I found the object of consumer webpart which I can catch and assign the current webpart to private member (_provider). But I expected it to be of type Webpart which is not and hence difficult to assign.
Whizsid
-
Friday, July 09, 2010 8:56 PMModerator
Hi Whizsid,
As tested & confirmed by you: GetRowData function [in the Consumer Webpart] is called before the Page Load event of the 1st Webpart [Row Provider], then we need to reconsider the design of our current WebParts.
I feel, below is the suitable way to achieve our requirement:
- Take all controls in one Webpart itself . In other words, the control which shall show the data once we select the row in the custom listviewbyquery Webpart can be part of the same Webpart itself.
- This shall be helpful in maintaining & also having better control over the events firing up.
Share your views.
AnjaliCH-MSFT -
Saturday, July 10, 2010 6:35 AM
Anjali,
This, indeed, is a good suggestion.
But that would compel me to implement consumer functionality as well on "listviewbyquery". Besides, I will have to take care of rendering for both the webparts.
Doable but I am looking around a design solution with IWebPartRow interface with no other (Consumer) webpart in it. Is there a way you could confirm the design (sequence of event firing) with other MS guys out there, just in case I am making a mistake ?
I tried following approach which is exactly opposite:
Break the functionality and separate Search controls in different webpart, resulting list in different webpart and Consumer would be the third webpart. Only problem with this approach is - I have to deal with WebPartManager and have to check out/In the page programmatically, which will not work when multiple people are working. Good thing about this approach is - it would let me leverage on existing list web parts and doesn't force me to implement ListViewByQuery.
Thanks,
Whizsid
- Edited by whizsid Tuesday, July 13, 2010 11:28 AM Formatting
-
Wednesday, July 14, 2010 2:43 PMModerator
Hi Whizsid,
The usual event follow in any connected webpart I believe is:
a. In connecting WebParts, the connections are activated in Page.LoadComplete event
b. The event flow will be: Page_Load, Post_Back, Page_LoadComplete
c. The generic view for the flow of events in the WebPart is:
i. PreInit
ii. Init
· WebZones register with the WebPartManager
· Static WebParts are loaded
iii. InitComplete
· Dynamic WebParts and connections are loaded
· Personalization data applied to Web Pars
iv. LoadViewState
v. Load
vi. LoadComplete
· Web Part connections are activated
vii. PreRender
viii. SaveStateComplete
· Extract & save personalization data
ix. Render
Few points I have seen in major issues with the connected webparts:
1. Major problem, comes arround when: we were trying to access the connection information in the Post_Back event (on the click of Link button); where the connection data is not yet received and activated. So, when we tried getting the method associated with event handler, it ended up in null value. The probable approach should be:
a. Provide a definition for "ConnectionConsumer" and "ConnectionProvider"
b. OnInit should create a handler for Page_Load & Page_LoadComplete (so Page.Load += new EventHandler(Page_Load); Page.LoadComplete += new EventHandler(Page_LoadComplete);)
c. Save some state in the button click handler (on click of the Query button), then use the data later on to determine the event.
d. Connections are activated in Page.LoadComplete; So now take the steps which we wanted to take in button click event handler. (Note: Check the value of the this.submit here. )
2. In short, make the following changes in the code:
a. Make changes in x.cs : add the event handler for Page_Load & Page_LoadComplete event in the OnInit event.
b. Store some value in the button click event handler (on the click of the Query Button) to determine the event is fired.
c. In the Page_LoadComplete event QuerySubmission class , check the value for this.submit and implement the business logic.
Code Snippet…
protected override void OnInit(EventArgs e) {
..............
this.Page.Load += new EventHandler(Page_Load);
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
.............
}
void Page_LoadComplete(object sender, EventArgs e) {
..........
if (this.Submit != null)
{
this.Submit(this, null);
}
}
void Page_Load(object sender, EventArgs e)
{ }
AnjaliCH-MSFT- Marked As Answer by Wayne FanModerator Monday, July 19, 2010 5:41 AM
- Unmarked As Answer by whizsid Monday, July 19, 2010 11:59 AM
-
Monday, July 19, 2010 12:15 PM
Anjali,
Due to other project work, I haven't got chance to implement this. But for sure, I had read your reply soon after it was posted.
There are few points, which I would like to run on this post (before I start implementation) :
- As you already know, first step for connection is to map the columns of Provider and Consumer webparts. The issue arises as soon as I click on connections -> Provide Rows -> web part selection etc... (from Context Menu). It errors at this stage itself and doesn't even let me move ahead !
- User defined control events (button click as mentioned in the above example) can be captured. But since SharePoint opens up a pop up page to do the (column) mapping - I am not sure which all events it does fire behind the seen ! This means: Even if I assign the event handlers in the OnInit event - I will still not have a control of the events fired by the (column mapping) functionality of SharePoint.
Thoughts ?
PS: I grealy appreciate your continued help on this.
Thanks,
Whizsid
- Edited by whizsid Tuesday, July 20, 2010 12:05 AM Formatting

