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?