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

i have created a web-part that user will define the url to render and after user insert the web part on the page it did not renders, user have to edit and enter the url and click apply or ok button in the prop.

here is my code i am using...

string SiteUrl = SPContext.Current.Site.Url;//Get the url of current site
                using (SPSite site = new SPSite(SiteUrl))
                    SPWeb web = site.OpenWeb();
                    SPFile webPartPage = web.GetFile(SPContext.Current.ListItemServerRelativeUrl);
                    SPLimitedWebPartManager webPartManager = webPartPage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                    web.AllowUnsafeUpdates = true;
                    pvwp.Title = WebPart.WebPartTitle;
                    pvwp.Description = WebPart.WebPartDescription;
                    if (string.IsNullOrEmpty(WebPart.WebPartContentLink.ToString()))
                        pvwp.ContentLink = "";

                    pvwp.Width = "10in";
                    pvwp.Height = "15in";

                    pvwp.ContentLink = WebPart.WebPartContentLink.ToString();
                    //webPartManager.AddWebPart(pvwp, "TOP", 0);
share|improve this question
just to clarify, where is this code running? is it in one of the webpart methods? – Rich Ross Sep 1 '11 at 23:45
the code is running on the usercontrol code behind – Nick Kahn Sep 2 '11 at 0:10
up vote 0 down vote accepted

To get the page viewer webpart to display in your webpart, just instantiate a new instance of the PageViewerWebPart object, set the properties with the value from the webpart property, and add it to the Controls for the webpart.

public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart

    private string _ViewerInformation = null;

    [System.ComponentModel.Category("PageViewer Filter")]
    [WebDisplayName("List with ViewerInformation")]
    [WebDescription("The list on the current site where the user information is stored.")]
    public string listWithViewerInformation
            if (_ViewerInformation == null)
                _ViewerInformation = string.Empty;
            return _ViewerInformation ;
        set { _ViewerInformation = value; }
    protected override void CreateChildControls()
        PageViewerWebPart pvwp = new PageViewerWebPart();
        pvwp.ContentLink = _ViewerInformation ;
share|improve this answer
PageViewerWebPart pvwp = new PageViewerWebPart(); – Nick Kahn Sep 2 '11 at 1:08
Rich, i am doing that if you read my code this.Controls.Add(pvwp); i am not sure i understand what you want to do... – Nick Kahn Sep 2 '11 at 1:08
So is the end goal is just to get a PageViewerWebpart onto your page? The properties for this PVVWP are being set by the user in the webpart properties panel. – Rich Ross Sep 2 '11 at 1:38
yes, the end goal is to display the website on the pageviewerwebpart. by default i am trying to set the website( but its not effecting when my insert my webpart. – Nick Kahn Sep 2 '11 at 1:43
answer updated based on these comments – Rich Ross Sep 2 '11 at 1:46

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.