I have a number of visual webparts and I'm looking to add these automatically to a page whenever that page gets created.

Is it best to add this to the page layout in a webpartzone?

I have tried creating a itemadded event receiver to the list but I can't seem to reference my custom webparts. I can view the webparts fine in the webpart gallery under the custom section but I can't work out how to reference these along with the WebPartManager methods.

ListViewWebPart lvp = new ListViewWebPart() works...

This doesn't compile - no reference to my custom webpart is available seemingly MyCustomWebPart wp = new MyCustomWebPart();

Any ideas? Ideally I'd like to do this in the receiver so I can ad

1 Answer 1


Yes - via a stapler feature that assigns the Web Part and inserts it into the page. Look up stapler to understand how that works (it's like an event handler on features). Next see these two CodePlex tools - all the code you need to insert a web part in a page is demonstrated there:

User rating web part: http://userratingwebpart.codeplex.com/ and

Add User Rating to Blog Site: http://addratingstoblogsite.codeplex.com/

  • Please don’t use signatures or taglines in your posts, or they will be removed. Every post you make is already “signed” with your standard user card, which links directly back to your user page... Read FAQs for more information Dec 15, 2012 at 5:47
  • Thanks, I have managed to get it working by adding a reference to my webparts.dll in my event receiver project. I'm not sure how this works though. When I deploy the wsp will it include the webparts.dll? If I update my webparts project how can I ensure that I am using the latest dll in the event receiver project? Is this all manual?
    – ringo747
    Dec 15, 2012 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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