2017-04-26 96 views
0

如何防止iframe中的网页在父页执行回发时重新加载? 下面是一个简单的.aspx页面。当我单击Button1时,会执行回发,将重新加载具有blank.aspx作为其源的iframe。我怎样才能防止这种情况发生?代码如下。停止在回传中重新加载iframe中的网页

 <div> 
     This is an empty page with a button to open a modal window in an iframe 
     <asp:Button ID="Button1" runat="server" Text="Postback" OnClick="Button1_Click" /> 
    &nbsp;<asp:Label ID="lblPostback" runat="server" Text="Initial Load"></asp:Label> 
       <!-- Trigger/Open The Modal --> 
<button id="myBtn" type="button">Open Modal</button> 

<!-- The Modal --> 
<div id="myModal" class="modal"> 

    <!-- Modal content --> 
    <div class="modal-content"> 
    <span class="close">&times;</span> 
    <p>Some text in the Modal..</p> 
     <iframe src="Site/Public/blank.aspx"></iframe> 
    </div> 

</div> 
     <script> 
     // Get the modal 
     var modal = document.getElementById('myModal'); 

     // Get the button that opens the modal 
     var btn = document.getElementById("myBtn"); 

     // Get the <span> element that closes the modal 
     var span = document.getElementsByClassName("close")[0]; 

     // When the user clicks on the button, open the modal 
     btn.onclick = function() { 
      modal.style.display = "block"; 
     } 

     // When the user clicks on <span> (x), close the modal 
     span.onclick = function() { 
      modal.style.display = "none"; 
     } 

     //When the user clicks anywhere outside of the modal, close it 
     window.onclick = function (event) { 
      if (event.target == modal) { 
       modal.style.display = "none"; 
      } 
     } 
    </script> 
    </div> 

回答

0

您可以在UpdatePanel中包装将在回发期间更改的元素。提供iframe然后在UpdatePanel之外,它回发时不应该重新加载。

+0

谢谢你的工作。 – enski