I created a webpart with many properties.
I want add it in EventReceiver and set properties.
How do use MyWebpart in EventReceiver?
|
I created a webpart with many properties. I want add it in EventReceiver and set properties. How do use MyWebpart in EventReceiver? |
|||||
|
|
You should use SPLimitedWebPartManager and it's AddWebPart method for this purpose. To create the SPLimitedWebPartManager object targeted to a specific page, use SPWeb.GetLimitedWebPartManager method. Code example:
Actually, this is a common way to add a webpart to a page in SharePoint. And I don't see why it would not work from within an event receiver. P.S. Also I suspect, that depending from the kind (sync/async) of the event receiver, you may have to run this code with elevated privilegies. |
|||||||||
|
|
Please find the answer below: http://stackoverflow.com/questions/419632/possible-to-load-a-web-part-inside-another I will reproduce the answer here (for convenience), It is not my code, I checked it and it should be OK.
This code needs some explaining... Please excuse me if it does not compile, I had to remove a fair bit of the original code, it was very implementation specific stuff. I've not shown the "config" class either, it's just a container for configuration of webparts, just a bunch of properties. There are 2 issues I'd like to discuss in more detail:
In our framework we also support stuff like dynamic property values etc., but that's for another day... Hope this all makes sense and can help somebody. |
|||||
|