c# - 弹出面板中的页面方法不会在 IE9 中第二次加载

标签 c# javascript internet-explorer-9 modalpopupextender pagemethods

我有一个主页,其中调用了一些pagemethod 来执行一些事件。 popuppanel(popuppanel 内容页面也有 pagemethods)在这个主页中使用来显示一些细节。如果多次执行相同的操作(即多次打开弹出面板),则它在 IE9 以外的所有其他浏览器 中都有效(甚至在 IE8 中也有效)。然而,第一次执行成功。下面提供了正在使用的代码。

Scriptmanager 用法如下:

<ajaxToolkit:ToolkitScriptManager runat="server" ID="TSCM1" EnablePageMethods="true" />

主页中的脚本:

function Clkd(){
     var ppnl=document.getElementById("if1");
     ppnl.src="Test1.aspx";
     $find('<%= MPE.ClientID %>').show();
}

function Clkd2(){
     var ppnl=document.getElementById("if1");
     ppnl.src="";
     $find('<%= MPE.ClientID %>').hide();
}

$(document).ready(function(){
     PageMethods.mainPageMethod("MainTest",cbackfn);
});

function cbackfn(str){
     alert(str);
}

分页方法:

 [System.Web.Services.WebMethod(EnableSession = true)]
        public static string mainPageMethod(String mainStr)
        {
            return mainStr + " Ok";
        }

Test1.aspx 页面详细信息(这是在弹出面板中加载的页面):

脚本代码如下:

$(document).ready(function(){
     PageMethods.Testpm("Test",fnd);
});

function fnd(str){
     alert(str);
}

分页方法:

 [System.Web.Services.WebMethod(EnableSession = true)]
        public static string Testpm(String alrt)
        {
            return "Ok";
        }

如果第二次执行同样的操作会抛出如下错误(仅限IE9)

SCRIPT5007: Unable to set value of the property '_UpdateProgress': object is null or undefined 
ScriptResource.axd?........

SCRIPT5007: Unable to get value of the property 'WebServiceProxy': object is null or undefined 
Test1.aspx, line 66 character 1

SCRIPT5007: Unable to get value of the property 'DomElement': object is null or undefined 
ScriptResource.axd?......, line 2 character 18851

SCRIPT5007: Unable to get value of the property 'add_init': object is null or undefined 
Test1.aspx, line 97 character 122

SCRIPT438: Object doesn't support property or method 'Testpm' 
Test1.aspx, line 11 character 4

Important Note: if main page does not have any pagemethods then its working fine. please help me out from this issue..

最佳答案

您应该添加相关的 HTML,这可能会帮助其他人帮助您。

好吧,我使用了您的代码并添加了缺失的代码,当我运行它时,它在包括 IE9 在内的所有浏览器中都运行良好。

请找到下面的代码:

主页(Default.aspx):

<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        function Clkd() {
            var ppnl = document.getElementById("if1");
            ppnl.src = "test.aspx";
            $find('<%= MPE.ClientID %>').show();
        }

        function Clkd2() {
            var ppnl = document.getElementById("if1");
            ppnl.src = "";
            $find('<%= MPE.ClientID %>').hide();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <cc1:ToolkitScriptManager runat="server" ID="scriptmanager1">
    </cc1:ToolkitScriptManager>
    <asp:Panel ID="pnl1" runat="server">
        <iframe id="if1"></iframe>
        <asp:Button ID="btnHidePopup" runat="server" Text="Hide" />
    </asp:Panel>
    <asp:Button ID="btnShowPopup" runat="server" Text="Show" OnClientClick="Clkd();" />
    <cc1:ModalPopupExtender ID="MPE" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnl1"
        DropShadow="true" OkControlID="btnHidePopup" OnOkScript="Clkd2()" CancelControlID="btnHidePopup">
    </cc1:ModalPopupExtender>
    </form>
</body>

测试.aspx:

<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            PageMethods.Testpm("Test", fnd);
        });
        function fnd(str) {
            alert(str);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <cc1:ToolkitScriptManager runat="server" ID="scriptmanageriframe" EnablePageMethods="true">
    </cc1:ToolkitScriptManager>
    Hello World this is game.
    </div>
    </form>
</body>

Test.aspx.ce(网络方法):

 [System.Web.Services.WebMethod(EnableSession = true)]
        public static string Testpm(String alrt)
        {

            return "Ok";
        }

希望对您有所帮助!

关于c# - 弹出面板中的页面方法不会在 IE9 中第二次加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589836/

相关文章:

c# - 锁定并验证还是验证并锁定?

javascript - 对话框关闭时如何清除对话框内的表格

javascript - 处理弹出窗口关闭的正确方法

javascript - 加载 Angular 库时 IE9 和 IE10 中的 Angular JS "SCRIPT5007: Object expected"错误

html - 如何在IE9中自定义下拉箭头

css - 菜单在 Internet Explorer 9 中不可见

c# - 类型 'DbConnection' 在未引用的程序集中定义。我不能添加引用?

c# - DirectorySeparatorChar 和 AltDirectorySeparatorChar 有什么区别

C# 和 Excel Interop 问题,保存 excel 文件不流畅

javascript - 在表的所有行中发出验证