SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In sharepoint2010 I am using a webpart and custom toolpart[]. The following code is for toolpart array

public override Microsoft.SharePoint.WebPartPages.ToolPart[] GetToolParts()
            ToolPart[] tp = new ToolPart[3];
            WebPartToolPart wptp = new WebPartToolPart();
            CustomPropertyToolPart cptp = new CustomPropertyToolPart();
            SampleToolPart customTP = new SampleToolPart();
            tp[0] = customTP;
            tp[1] = cptp;
            tp[2] = wptp;

            return tp;

When I edit the webpart user can configure data to be shown in the webpart page. But I am not able to view the recent changes in the page after clicking apply and Ok only the modified data is shown in the page. In the CreateChildControls() event only I have added the controls in it.

Could anyone help me to solve this issue ?

share|improve this question
Can you clarify "But I am not able to view the recent changes in the page after clicking apply and Ok only the modified data is shown in the page." please – Ryan Jan 23 '12 at 16:44
up vote 3 down vote accepted

This is probably due to your misunderstanding of the ASP.NET Page Life cyle.

Long long story short it goes through these events (simplified)

  • Constructor
  • OnInit
  • OnLoad
  • CreateChildControls
  • Apply Changes
  • OnPreRender
  • Render

I suspect (not all code posted) that you're creating your controls AND setting their values in CreateChildControls.

However, the ApplyChanges method (where you pick up changes in the toolpart) happens at OnPreRender.

In other words you've already set what you're going to be sending back to theuser before you pick up any changes.

Setup some breakpoints in the relevant sections and try it out.

How to fix?

  • Create controls in normal place but don't set their value until OnPreRender/OnRender.
  • Or if you've got complex controls (i.e. settings on toolpart changes what controls you need to create) then you can remove the existing controls you just created and re-create them after OnApply.

See also

share|improve this answer
Thanks for your reply.I have gone through the links provided by you it help me to resolve the issue.The recent changes are reflecting in the webpart by clicking Ok only.I am having the grid in the webpart user can configure datasource(Sharepoint list) for the grid.For example the grid has 10 items with paging(2 Pageindex in the grid)when I go for the next page in the grid(postback occurs the next 5 items from the grid has been assigned as datasource) but it not get reflected in the webpart page. – Ramalingam Jan 24 '12 at 13:48
Partially the issue is resolved in the sense, I am having a grid in the webpart and it has 10 items (pagesize is 5 i.e two pages). When I go for the second page in the grid the data is assigned to the datasource,The page gets postback but it doesn't get reflect in the webpart page. Could you help me to resolve the issue ? – Ramalingam Jan 24 '12 at 14:39
Thanks Ryan for your reply. I have resolved the issue by adding the controls in the CreateChildControls() method and assign the value for the control in the OnPreRender() method – Ramalingam Jan 25 '12 at 10:47

Your Answer


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.