Lia*_*iao 11 asp.net dynamic include
这是我在ASP.NET中尝试做的事情:
创建一个名为Main.aspx的页面.这个页面有一个DIV和一个按钮.
浏览器加载Main.aspx.然后当我单击按钮时,我想动态地将页面Page99.aspx加载到Main.aspx中的DIV中,但是没有Main.aspx需要回发.
因此,Main.aspx加载一次,此后Main.aspx中显示的所有内容将来自不同的.aspx页面.
PS.我正在寻找上面的解决方案,但不使用框架.
更新1 我应该提到Page99不是一个简单的HTML页面.它将包含Web控件.
如果您不想使用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>
Run Code Online (Sandbox Code Playgroud)
据我所知,除非使用 iframe,否则无法将一个 aspx 页面加载到另一个页面中。
对于回发或 ajax,您可以使用 UserControls (ascx)。它们可以包含与页面几乎相同的内容,或者使用母版页。
如果您希望没有回发,ajax 可能是可行的方法,但同样,它不允许您将 aspx 页面加载到另一个页面中,而只能更改您所在页面的内容(除其他外)。
我不确定其他的 Web 开发平台,他们可能有一个更接近你想要做的解决方案,所以如果 ASP.NET 不是“必须”,你应该考虑检查其他平台。