将aspx页面加载到另一个aspx页面的div中 [英] Load aspx page into div of another aspx page
本文介绍了将aspx页面加载到另一个aspx页面的div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我有一个带有div标签的主aspx页面和另一个带有一些文本的简单aspx页面。如何在单击链接时将简单页面加载到主页面的div中?这就是我到目前为止所做的......
Hi all, i have one main aspx page with a div tag and another simple aspx page with some text on it. How can i make the simple page load into the main page's div when a link is clicked? This is what i have done so far...
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="public_site/StyleSheet2.css" media="screen"/>
<script type="text/javascript">
function load(link)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("mydiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","about.aspx?is_ajax=1&link="+link,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="bg">
<img src="/public_site/img/background.png" alt="" />
</div>
<div class="menu">
<ul>
<li class="menu_link"><a href="home_page.aspx">HOME</a> |</li>
<li> NEWS </li><li>|</li>
<li style="color:#0B4C5F;"> ABOUT US</li> <li>|</li>
<li> FAQ |</li>
<li> DOWNLOADS |</li>
<li> CONTACT US |</li>
<li> RETAILERS |</li>
<li> MEMBERS</li>
</ul>
</div>
<div class="block">
<ul class="menu2" style="text-align:center;">
<li class="menu_link"><a href="about.aspx" style="cursor:pointer; color:#01DFD7;">Buying Club</a></li> <li style="color:#0B4C5F;">|</li>
<li style="color:#0B4C5F;"><a onclick="load('1');" style="cursor:pointer;"> Network Marketing</a> |</li>
<li style="color:#0B4C5F;"> Opportunity |</li>
<li style="color:#0B4C5F;"> Ubuntu |</li>
<li style="color:#0B4C5F;"> Affiliations |</li>
<li style="color:#0B4C5F;"> Credentials </li>
</ul>
<hr />
<div id="mydiv" class="content">
<h3 class="header2">Imagine</h3>
<p style="margin-left:8%;">
A FULL grocery cupboard and fridge ALL the time, everything you want to enjoy and
AFFORDING it!
</p>
<h3 class="header2">We have a plan</h3>
<p style="margin-left:8%;">
Bringing you an EXCELLENT CONCEPT, an AMAZING SERVICE and SAVINGS, allowing you to
EARN.
</p>
<h3 class="header2">Who is DreamTeam buying club...</h3>
<p style="margin-left:8%;">
We are an independent marketing organisation based from the Eastern Cape in South
Africa. Using technology and participating retailers to offer our members a wide range of
products from which to purchase and receive rewards and rebates, linked to a
business opportunity to build your own business helping you increase your income…
</p>
<h3 class="header2">What is DreamTeam buying club</h3>
<ul style="margin-left:5.3%;">
<li>A place for faily and friends to help one another.</li>
<li>A place where people contribute to improving their and others lives.</li>
<li>A place for cost effective and easy shopping.</li>
<li>A safe place to put money aside every month for daily needs.</li>
<li>A safe place keep to shopping money.</li>
</ul>
</div>
</div>
</form>
</body>
</html>
后面的代码:
And the code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["is_ajax"] != null)
{
Response.Clear();
if (Request.QueryString["link"] == "1")
{
Response.Write("Hello World");
}
Response.End();
}
}
这会在主页的div中返回hello world我怎么能让它返回简单的页面?任何帮助将不胜感激,请提前感谢。
This returns hello world in the main page's div how can i get it to return the simple page? Any help will be much appreciated, thanking you in advance.
推荐答案
我建议使用jQuery,我做了几次这样的事情,它使它成为现实非常简单。
http://api.jquery.com/load/ [ ^ ]
在你的例子中,它将是如此简单:
I would recommend using jQuery for this, I have done something like this a few times and it makes it very easy.
http://api.jquery.com/load/[^]
In your example it would be something as simple as:
( #mydiv)。load( pageToLoad.aspx #container);
("#mydiv").load("pageToLoad.aspx #container");
PageToLoad.aspx:
PageToLoad.aspx:
pageToLoad.aspx:
<html>
<body>
<div id="container">
<!--stuff goes here -->
</div>
</body>
</html>
这篇关于将aspx页面加载到另一个aspx页面的div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文