I am trying to get an AJAX ModalPopupExtender to work in a SharePoint web part but I'm not having any luck at all.

I thought it might be something else in my web part causing it so I've created a small test web part and it is still not displaying.

The problem is that when you click the button the modal popup is simply not displayed at all and the page just performs a postback.

I have read lots of people talking about adding a DOCTYPE tag to the master page - but I understand this is because the modal panel is never displayed in the correct place. Despite this I still want to get it working just because I've come this far. I have tried the DOCTYPE tag and this still does not make the modal show up.

If anyone could offer a solution as to why it will not display or perhaps another solution to display a dialog similar to the ModalPopupExtender then I would be grateful.

My SharePoint site's web.config is .NET 3.5 'enabled' and there is a ScriptManager present on the page.

I've posted all the code below:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using AjaxControlToolkit;

namespace TestWebPart
    public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
        ModalPopupExtender modal;

        public WebPart1()

        protected override void CreateChildControls()

            Button btnTest = new Button();
            btnTest.Text = "Show the Modal!";
            btnTest.ID = "btnTest";
            btnTest.Click += new EventHandler(btnTest_Click);

            Button btnHidden = new Button();
            btnHidden.ID = "btnHidden";
            btnHidden.Text = "Some Text";

            Panel contents = new Panel();
            contents.CssClass = "modalPopup";
            contents.ID = "contents";

            TextBox txtTest = new TextBox();
            txtTest.Text = "Testing";

            modal = new ModalPopupExtender();
            modal.ID = "mpe";
            modal.BackgroundCssClass = "modalbackground";
            modal.PopupControlID = "contents";
            modal.TargetControlID = "btnTest";
            modal.CancelControlID = "btnHidden";
            modal.X = 200;
            modal.Y = 200;

            // TODO: add custom rendering code here.
            // Label label = new Label();
            // label.Text = "Hello World";
            // this.Controls.Add(label);

        protected void btnTest_Click(object sender, EventArgs e)

4 Answers 4


Just a wild guess

    protected void btnTest_Click(object sender, EventArgs e)
  • Thanks Geoff but this is in the code behind so 'mpe' has not been defined. In the code the modalpopup is defined as 'modal'. Calling Show doesnt seem to make a difference :-(
    – Anonymous
    Feb 1, 2010 at 9:02

HI Alex, Have you solved this issue. I am facing similar problem. Could you please share the solution.


Here is a good example on how to use the ModalPopupExtender in a WebPart using-a-modalpopupextender-in-a-sharepoint-webpart-class

It helped me a lot as most of the other examples used asp.net.


I tripped across this post when trying to find answers to a different question I had months ago, might be of help: Getting the ModalPopupExtender to work in SharePoint 2007

  • Thanks James - Ill have a look at this post when I get some time and let you know how I get on
    – Anonymous
    Jun 7, 2010 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.