0

We have a SharePoint site, where we want to load an iframe. Now our problem is, that the iframe needs to have a dynamic URL. How can we achieve that?

At the moment we are using an EventReceiver which generates a webpart.

To add some more details, we generate the webpart in an EventReceiver what we want to achieve is, that we modify the iframe's src-attribute on every request to the webpart.

The EventReceiver is of type SPFeatureReceiver and here is some code:

   public override void FeatureActivated(SPFeatureReceiverProperties properties)
   {
   var web = properties.Feature.Parent as SPWeb;

   if (!PageUtil.PageExists(web, "somepage.aspx"))
   {
       PageUtil.AddWebpartPage(web, "Service Portal", "somepage.aspx");
   }

   // Add site viewer webpart
   PageViewerWebPart webPart = new PageViewerWebPart();

   if (!PageUtil.WebpartExists(web, webPart, string.Format("{0}/{1}", "SitePages", "somepage.aspx")))
   {
       webPart.ContentLink = "contenturl";
       webPart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
       PageUtil.AddWebpartToPage(web, webPart, "SitePages/somepage.aspx", "main", 0);
   }
   }
  • Eventreceivers are async,i donot think u can achive this in eventreceiver, try a different way or please elaborate more about your scenario – Shiva May 21 '15 at 10:44
  • @Shiva I added some details – Knerd May 21 '15 at 10:47
  • Can't you use Client Side Object model in that case? It will be much more easier and implement and maintain. – Amal Hashim May 21 '15 at 10:56
  • @AmalHashim sadly no, because we need to have the src set before the page is rendered. – Knerd May 21 '15 at 10:57
  • @AmalHashim I added some code. – Knerd May 21 '15 at 11:01

Your Answer

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

Browse other questions tagged or ask your own question.