My Technical Notes

Wednesday, 12 June 2013

Ajax Toolkit's ModalPopupExtender hiding page content

On an ASP.NET page I was working on, I put a Ajax Toolkit ModalPopupExtender instance. As part of a Button Click event I called the Show() method, after which the content of the page disappeared and thereafter the dialog appeared in its place.

The one clue I had to go by was the FireBug error which occurred each time:

TypeError: (intermediate value)(...) is not a function

It turns out that this error has something to do with the a known error to do with ValidationSummary and ModalPopupExtender. See this answer on StackOverflow by Aaron Hoffman.

The solution is to define and use a subclass of the ValidationSummary class which inserts a semi-colon in the JavaScript.

public class AjaxValidationSummary : ValidationSummary
    protected override void OnPreRender(EventArgs e)
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);

No comments: