popuppanel中的Pagemethods没有在IE9中第二次加载

Pagemethods in popuppanel does not load the second time in IE9

本文关键字:IE9 第二次 加载 中的 Pagemethods popuppanel      更新时间:2023-09-26

我有一个主页,它调用了一些pagemethod来执行一些活动。popuppanel(popuppanel内容页也有pagemethods)用于显示一些详细信息。如果多次执行相同的操作(即多次打开弹出面板),则在除IE9之外的所有其他浏览器中工作(即使在IE8中也工作)。但是,第一次执行是成功。下面提供了正在使用的代码。

脚本管理器使用如下:

<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

重要提示:如果主页面没有任何页面方法,则工作正常。请帮我解决这个问题。。

您应该添加相关的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(Webmethod):

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

我希望它能有所帮助!

U可以尝试不同的弹出

例如:

  1. asp:ModalPopupExtenderajaxtoolkit中也可用
  2. jquery对话框弹出

我更希望您使用jquery对话框弹出窗口,而不是使用您编写的c#和jquery代码中的相同web方法的ajaxpopup面板。

在MPE上使用ClientIdMode="Static",并在$find()中直接使用MPE id。

ASPX代码:

<asp:ModalPopupExtender ID="modalpopup" ClientIDMode="Static" runat="server" CancelControlID="btnCancel"
OkControlID="btnOkay" TargetControlID="Button1" PopupControlID="Panel1" 
        Drag="true" >
</asp:ModalPopupExtender>

Javscript代码:

$find('modalpopup').show(); // to show popup
$find('modalpopup').hide(); // to hide popup

IE9在两个页面(主页、弹出面板页面)中都有页面方法时,页面方法有问题。

您可以在webservice(.asmx)文件中使用页面方法

我试过了以下几种:

defaultpage.aspx

<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
      function fnd123(str){
          alert(str);
    }
     function objFailed1(data) {
     fnd123(data);
      }
     function objGot1(data) {
                        fnd123(data.d);
             }
    function Clkd(){
    var ppnl=document.getElementById("if1");
    $.ajax({
             url: "Testser.asmx/GetData",
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             data:'{"FileName":"Data from default page"}',
             type: 'POST',
             success:objGot1,
             error: objFailed1
         });
    ppnl.src="Test1.aspx";
     $find('MPE').show();
    }

     function Clkd2(){
    var ppnl=document.getElementById("if1");
     ppnl.src="";
     $find('MPE').hide();
     //PageMethods.clearPageData("/Test1.aspx",fnd1);
    }

    </script>
</head>
<body>
    <form id="form1" runat="server">
      <asp:ToolkitScriptManager runat="server" ID="ToolkitScriptManager1" EnablePageMethods="true" EnablePartialRendering="false"/>
    <div>
    <input type="button" onclick="javascript:Clkd();return false;" value="Click" />
    <div>
        <asp:ModalPopupExtender ID="MPE" PopupControlID="popupPanel" PopupDragHandleControlID="popupPanel"
            runat="server" Enabled="True" TargetControlID="btnOk" CancelControlID="BtnCancel"
            BackgroundCssClass="PopupBackground" Drag="True" EnableViewState=true >
        </asp:ModalPopupExtender>
        <asp:Button Style="display: none" ID="BtnOk" runat="server"></asp:Button>
        <asp:Button Style="display: none" ID="BtnCancel" runat="server"></asp:Button>
    </div>
    <div>
        <asp:Panel ID="popupPanel" runat="server" Style="overflow: hidden; z-index: 100000;
            display: none; background-color: White; filter: alpha(opacity=100); opacity: 1.0;
            height: auto;">
            <asp:Panel ID="pnlLoginHeader" runat="server" CssClass="" Style="display: none;">
                <table width="100%">
                    <tr style="text-align: center">
                        <td style="width: 97%;">
                            <p class="popupTitle">
                                <asp:Label runat="server" ID="lblTitle" Text=""></asp:Label>
                            </p>
                        </td>
                        <td style="width: 3%;">
                            <p style="text-align: right;">
                                <span id="lblPopupClose" style="cursor: pointer; color: White">Close</span>
                            </p>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <iframe id="if1" src="" class="" style=""></iframe>
        </asp:Panel>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Redirect" />
    </div>
    </div>
    </form>
</body>

Test1.aspx

<head id="Head1" runat="server">
    <title>Untitled Page</title>
        <script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script language="javascript" type="text/javascript">
          function fnd(str){
          alert(str);
    }
     function objFailed1(data) {
     fnd(data);
      }
     function objGot1(data) {
                        fnd(data.d);
             }
     function Clkdwebservice(){
    $.ajax({
             url: "Testser.asmx/GetData",
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             data:'{"FileName":"Data from test page"}',
             type: 'POST',
             success:objGot1,
             error: objFailed1
         });
   }
    </script>
</head>
<body>
    <form id="form1" runat="server" enableviewstate="false">
    <asp:ToolkitScriptManager runat="server" ID="ToolkitScriptManager1" EnablePageMethods="true" />
    <div>
        <input type="button" onclick="javascript:Clkdwebservice();return false;" value="Click" />
         <input type="button" onclick="javascript:parent.Clkd2();return false;" value="Close" />
    </div>
    </form>
</body>

测试程序.asmx.cs

[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    [ToolboxItem(false)]
    public class Testser : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public String GetData(String FileName)
        {
                     string msg = FileName;
            return msg;
        }
    }

它对我来说运行良好。请检查它的