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'm trying to add a webpart to a "Dispform.aspx" of a list in Sharepoint Designer. I can add ootb webparts without any problem, but mine just won't work. By the way, I can add the web part normally inside a page in IE. Here's the code of one plain web part I tried adding (it made SPD crash) :

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;

namespace Project.SharePoint.Internet.Base
{
    [Guid("1e9d4769-611b-4fa4-8f1c-bb54c9138233")]
    public class PlainWP : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private bool _error = false;
        private string _myProperty = null;

        public PlainWP()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Create all your controls here for rendering.
        /// Try to avoid using the RenderWebPart() method.
        /// </summary>
        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {

                    base.CreateChildControls();

                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        /// <summary>
        /// Ensures that the CreateChildControls() is called before events.
        /// Use CreateChildControls() to create your controls.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!_error)
            {
                try
                {
                    base.OnLoad(e);
                    this.EnsureChildControls();

                    // Your code here...
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        /// <summary>
        /// Clear all child controls and add an error message for display.
        /// </summary>
        /// <param name="ex"></param>
        private void HandleException(Exception ex)
        {
            this._error = true;
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl(ex.Message));
        }
    }
}

I tried debugging the code in the Web part. When I add the Web Part in SPD, it does go to my breakpoint. The constructor is called once, then CreateChildControls, Constructor, CreateChildControls, Constructor, then crashes.

Am I missing an override or something?

share|improve this question

closed as too localized by Alex Angas Jun 6 '11 at 7:10

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Please clarify if it is SPD 2007 or SPD 2010. –  Wictor Wilen MCA MCM MVP Jul 15 '10 at 13:35
    
SPD 2007. Like i've said, it works on another computer and I never found a solution for my computer. –  Anonymous Aug 11 '10 at 17:08

3 Answers 3

Try implementing IDesignTimeHtmlProvider as I mentioned in my blog here: http://www.thelineberrys.com/default-category/viewing-sharepoint-webparts-in-frontpage-2.html

Also, maybe try commenting out the onload function.

share|improve this answer
    
I'll try that thanks! –  Anonymous Jul 15 '10 at 13:17
    
The breakpoint in the IDesignTimeHtmlProvider is never called and SPD still chrases :( I'm going to try on another server. –  Anonymous Jul 15 '10 at 13:32
    
Is it SharePoint 2010? If so I don't think that SPD2010 uses IDesignTimeHtmlProvider, it renders the WP "for real". –  Wictor Wilen MCA MCM MVP Jul 15 '10 at 13:34

Did you add a safe control entry?

share|improve this answer
    
There's an entry for all the classes of the DLL yes –  Anonymous Jul 15 '10 at 13:16
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Hugh Wood Nov 27 '12 at 21:07

Have you tried your class with only a CreateChildControls? Nothing in the constructor, no exception handling, just the CreateChildControls method.

share|improve this answer