2

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?

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
0

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.

  • 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
0

Did you add a safe control entry?

  • There's an entry for all the classes of the DLL yes – Anonymous Jul 15 '10 at 13:16
0

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