The follow code results in an "Object Expected" javascript error:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "
http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Panel runat="server" id="ModalTest" style="width:200px;height:200px;border:1px;">
<span>This is a test</span>
<asp:TextBox runat="server" ID="txtTestInput" ></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="rfvTestInput" ControlToValidate="txtTestInput" />
</asp:Panel>
<asp:Button ID="btnPop" runat="server" Text="Submit" />
<asp:ValidationSummary ID="vs" runat="server" />
<cc1:ModalPopupExtender ID="MPE" runat="server" TargetControlID="btnPop" PopupControlID="ModalTest" >
</cc1:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
MPE.Show();
}
</script>
The cause of the error can be tracked back to two specific statements of code that get emitted:
document.getElementById('vs').dispose = function() {
Array.remove(Page_ValidationSummaries, document.getElementById('vs'));
}
(function() {var fn = function() {AjaxControlToolkit.ModalPopupBehavior.invokeViaServer('MPE', true); Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);})();
The first part is the result of the RegisterValidatorDeclaration from the "BaseValidator" class. The second line is the results of the ChangeVisibility method on the ModalPopupExtender. The error occurs because the anonymous function from the first statement IS NOT TERMINATED with a semicolon AND the run time views the second line as part of the same statement (due mostly to the fact that it is a weird construct...an immediate anonymous function). Correct output should appear as follows:
document.getElementById('vs').dispose = function() {
Array.remove(Page_ValidationSummaries, document.getElementById('vs'));
};
(function() {var fn = function() {AjaxControlToolkit.ModalPopupBehavior.invokeViaServer('MPE', true); Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);})();
Pat