Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 = "http://www.cnn.com";
                    }

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

                    pvwp.ContentLink = WebPart.WebPartContentLink.ToString();
                    //webPartManager.AddWebPart(pvwp, "TOP", 0);
                    this.Controls.Add(pvwp); 
                } 
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 –  Abu Hamzah Sep 2 '11 at 0:10

1 Answer 1

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.

[ToolboxItemAttribute(false)]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{

    private string _ViewerInformation = null;

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [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
    {
        get
        {
            if (_ViewerInformation == null)
            {
                _ViewerInformation = string.Empty;
            }
            return _ViewerInformation ;
        }
        set { _ViewerInformation = value; }
    }
    protected override void CreateChildControls()
    {
        PageViewerWebPart pvwp = new PageViewerWebPart();
        pvwp.ContentLink = _ViewerInformation ;
        this.Controls.Add(pvwp);
    }
}
share|improve this answer
    
PageViewerWebPart pvwp = new PageViewerWebPart(); –  Abu Hamzah 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... –  Abu Hamzah 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(cnn.com) but its not effecting when my insert my webpart. –  Abu Hamzah Sep 2 '11 at 1:43
    
answer updated based on these comments –  Rich Ross Sep 2 '11 at 1:46

Your Answer

 
discard

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.