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 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
{
    [Guid("6716fe47-4797-4542-aca0-c07bff0cfa17")]
    public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
    {
        ModalPopupExtender modal;

        public WebPart1()
        {
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

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

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

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

            TextBox txtTest = new TextBox();
            txtTest.Text = "Testing";
            contents.Controls.Add(txtTest);

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

            // 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)
        {
            modal.Show();
        }
    }
}
share|improve this question
add comment

4 Answers

Just a wild guess

    protected void btnTest_Click(object sender, EventArgs e)
    {            
       mpe.Show();
    }
share|improve this answer
    
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 '10 at 9:02
add comment

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

share|improve this answer
1  
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. –  Stuart Pegg Sep 6 '12 at 21:49
add comment

I tripped across this post when trying to find answers to a different question I had months ago, might be of help: http://bloggingabout.net/blogs/rick/archive/2008/03/14/getting-the-modalpopupextender-to-work-in-sharepoint-2007.aspx

share|improve this answer
    
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 '10 at 8:28
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.