Asp.net

如何在執行時動態顯示另一個 ASPX 的 DIV 中的 ASPX?

  • September 16, 2020

這是我在 ASP.NET 中嘗試做的事情:

創建一個名為 Main.aspx 的頁面。這個頁面有一個 DIV 和一個按鈕。

瀏覽器載入 Main.aspx。然後,當我點擊按鈕時,我想將頁面 Page99.aspx 動態載入到 Main.aspx 中的 DIV 中,但沒有 Main.aspx 需要回發。

因此,Main.aspx 載入一次,此後 Main.aspx 中顯示的所有內容都將來自不同的 .aspx 頁面。

**附言。**我正在尋找上述解決方案,但不使用框架。

更新 1 我應該提到 Page99 不是一個簡單的 HTML 頁面。它將包含 Web 控制項。

據我所知,除非使用 iframe,否則無法將一個 aspx 頁面載入到另一個頁面中。

使用回發或 ajax,您可以改用 UserControls (ascx)。它們可以包含幾乎與頁面相同的內容,或者使用 MasterPage。

如果您希望沒有回發,ajax 可能是要走的路,但同樣,它不允許您將一個 aspx 頁面載入到另一個頁面中,只能更改您所在頁面的內容(以及其他內容)。

不過,我不確定其他用於 Web 開發的平台,它們可能有更接近您想要做的解決方案,所以如果 asp.net 不是“必須”,您應該考慮查看其他平台。

如果你不想使用 iFrame,你可以很好地使用 HTML 的 Object 元素。按照這裡查看和 html 範例。您也可以很好地將其用於 aspx,並進行一些更改,例如將 OnClientClick 屬性用於 aspx 按鈕等。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>mouseover image position</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<style type="text/css">
/*<![CDATA[*/
body
  {
   background-color:#aaaaff;
  }
#one
  {
   position:absolute;
   left:50%;
   top:50%;
   margin:-150px 0 0 -250px;
  }
object
  {
   width:500px; 
   height:300px; 
   border:solid 1px #000000;
  }
/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[
// written by: Coothead
function updateObjectIframe(which){
   document.getElementById('one').innerHTML = '<'+'object id="foo" name="foo" type="text/html" data="'+which.href+'"><\/object>';
}

//]]>
</script>

</head>
<body>

<div id="one">
<object id="foo" name="foo" type="text/html" data="http://www.w3schools.com/"></object>
</div>
<div>
<a href="http://www.google.com" onclick="updateObjectIframe(this); return false;">this is an object test not an iframe test</a>
</div>

</body>
</html>

引用自:https://stackoverflow.com/questions/2099214