Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I currently have a webpart with a table which loads documents in itself. Every row has a checkbox control in the first cell. (Default: unchecked)

I am using a second webpart which has a button. If the button is clicked the webpart should load all document rows which are checked. I want the button webpart to show this results.

The first problem i encountered was that once everything was loaded and the

void button_Click(object sender, EventArgs e)

event was fired the second webpart lost the first webpart as a provider. I solved this issue by saving the provider in

Page.Session["provider"]

But this saves the old provider with the old table in which no row is selected. How do i make sure that the changes in the first webpart will be saved when a event from the second webpart is fired? And will be available in the second webpart for use.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

If the provider you're talking about is set up using web part connections then a post back shouldn't break that link, but you may be breaking the golden rule regarding web part connections which is:

The provider should be able to provide the data as early as possible
The consumer should use the data as late as possible

This is to avoid the race condition where the consumer tries to use the data before the provider has them.

So your second web part may not be able to use the data in the click event which is very early in the page life cycle. It can the instead set a flag which you can then use in a later event like 'OnPreRender`

share|improve this answer
    
These 2 webparts are indeed currently set up using web part connections. And on first load the second webpart can find the provider. Clicking the button in the second webpart somehow breaks the link. In the click event i check for the provider. If (Provider == null) comes out true in the click event. –  user1746525 Jan 4 '13 at 10:47
    
What about in the OnPreRender event? –  Per Jakobsen Jan 4 '13 at 10:50
    
In OnPreRender is does find the provider. On first load aswell on the click event. –  user1746525 Jan 4 '13 at 10:54
    
So if all you do in the click event is to set a flag that the button was clicked, then you can check that in a later event when the provided is provided and ready to provide the data –  Per Jakobsen Jan 4 '13 at 11:04
    
It did solve the issue of losing the provider. But i still have the issue where the changes (unchecking / checking the checkbox) in the first webpart are not saved. And this might still be as you said be caused because i breaak the golden rule. –  user1746525 Jan 4 '13 at 12:03
add comment

I agree with per!

You can check out my answer here on another post :) it has connectable webparts and saving to sessions state:

how to have connectable web part on two pages?

hope it helps!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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