【问题标题】:Pagemethods in popuppanel does not load the second time in IE9popuppanel中的Pagemethods在IE9中没有第二次加载
【发布时间】:2013-09-06 13:02:51
【问题描述】:

我有一个主页,其中调用了一些 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

重要提示:如果主页没有任何 pagemethods,那么它可以正常工作。 请帮我解决这个问题..

【问题讨论】:

  • 除了&lt;%= MPE.ClientID %&gt; 之外,您是否尝试过使用不同的方法来提供 MPE 的客户端 ID? &lt;%= %&gt; 是 Response.Write,它与 MS Ajax 的东西不兼容
  • 是的,我试过但同样的错误
  • 你能发布修改后的代码吗?
  • 只需将 '' 更改为 'MPE' 并使用 '#MPE' 进行检查
  • 不,它仍然必须是有效的客户 ID。作为测试,您能否在呈现的 HTML 中验证真实的客户端 ID 并尝试使用它?例如。它可能类似于$find('Parent_ctl00_MPE').show()

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


【解决方案1】:

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

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

请查看以下代码:

主页(默认.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>

Test.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";
        }

希望对你有帮助!

【讨论】:

  • 请检查 ie9。它第一次工作正常。再次隐藏弹出面板尝试显示其获取错误。
  • 它在 IE9 中运行良好,每次打开它。完全没有错误。只需在新项目中使用我的代码并尝试。
【解决方案2】:

你可以尝试不同的弹出窗口

例如:

  1. asp:ModalPopupExtender 也可在 ajaxtoolkit
  2. jquery 对话框弹出。

【讨论】:

    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      在 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>
      

      JavaScript 代码:

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

      【讨论】:

        【解决方案5】:

        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>
        

        Testser.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;
                }
            }
        

        它对我来说工作正常。请检查一下

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多