How to dynamically change link in Page Viewer Web Part SharePoint 2010?


  • Newbie Question:


    a) Created: Two Site Pages page 1 & page 2

    b) Page 1: Includes simple hyperlink text Example - Home | About Us | Contact etc

    c) Page 2: Includes Page Viewer Web Part that includes link to an existing web site (this site has all of the pages) and the olde site is shown in SharePoint site


    a) I want the users to click on Page 1 - About Us etc

    b) The View on Page 2 - page viewer link should be dynamically updated to About Us . If user clicks on contact us on Page 1..the page 2 view should change dynamically to Contact US


    a) How do I dynamically update the links in Page Viewer web part using minimal coding (if possible)

    Any Guidance will be greatly appreciated.

    Sunday, August 26, 2012 2:58 AM


All replies

  • The Page Viewer Web Part is basically an HTML IFRAME. You can use a Content Editor Web Part with an IFRAME and a little JavaScript to do what you want.  Here's one example:

    The article is for SP 2007, but should work fine for 2010. When working with the SP 2010 Content Editor Web Part it is best to put your JS and HTML in a text file stored in a library, and then link the web part to it. See here:

    Mike Smith

    Sunday, August 26, 2012 3:16 AM
  • Hello,

    You can also used the another appoch,

    Create your custom webpart , then add the PageViewer Webpart at run time,Create webpart property for the custom webpart to change the url and add the PageViewer webpart runtime,

    I have created the custom webpart property to specified the url at the tine of edit the webpart

    Here is the code

    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using System.Collections;
    using Microsoft.SharePoint.Publishing.WebControls;
    using Microsoft.SharePoint.WebPartPages;
    namespace MyNameSpace.MyPageViewer
    	public class MyPageViewer : System.Web.UI.WebControls.WebParts.WebPart
    		private string _customUrl = "http://yourdefaulturl";//Specified default url		
    		, Personalizable(true)
    		, Bindable(true)
    		, Browsable(false)
    		, DefaultValue("")
    		, Category("Custom Page Viewer Properties")
    		, WebPartStorage(Storage.Shared)
    		, FriendlyName("PageViewer URL")
    		, Description("PageViewer URL")]
    		public string CustomUrl
    			get { return _customUrl; }
    			set {if (string.IsNullOrEmpty(value) == false) {  _customUrl = value; } }
    		public MyPageViewer()
    			this.ChromeType = PartChromeType.None;
    		protected override void OnInit(EventArgs e)
    		protected override void CreateChildControls()
    			string pageViewerUrl = CustomUrl;
    			Microsoft.SharePoint.WebPartPages.PageViewerWebPart pageViewerWebPart = new Microsoft.SharePoint.WebPartPages.PageViewerWebPart();
    			if (!string.IsNullOrEmpty(pageViewerUrl))
    				pageViewerWebPart.ContentLink = pageViewerUrl;
    			pageViewerWebPart.ChromeType = PartChromeType.None;
    			pageViewerWebPart.Height = "382";
    			pageViewerWebPart.Width = "682";
    		protected override void OnLoad(EventArgs e)
    		protected override void OnPreRender(EventArgs e)

    Hope this will help you

    Hiren Patel | Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

    Sunday, August 26, 2012 3:47 AM
  • Thank you Mike your solution worked like a charm. 
    Monday, August 27, 2012 2:12 AM
  • Hi there mate. It saved me a lot of time. It was perfect.
    Monday, November 05, 2012 3:44 AM
  • Hi Hiren,

    Thanks for the code. It helped a lot.


    Regards, Keerthi Suryadevara

    Monday, June 23, 2014 8:35 AM