使用Ajax.NET Professional框架,如何在页面test1的一个div里显示页面test2?
解决方案 »
- 求IP 地址数据库
- 【非哥】
- 求救,类的定义与调用
- 请教判断是否为汉字的正则表达式如何写呢?
- 怎么我的连接都对不上呢? 急用,请帮忙
- DataGrid控件的深层次问题,有那位知道,请指点!
- 代码和界面是分开的, 在代码中定义了i,在界面中用到i 说"未定义",怪,怎么解决,谢谢.
- 如何使用XmlTextWrite在xml文件中插入一个新结点,当我用WriteStartElement时xml文件中的原有内容就会被冲掉
- 关于提交成功 后 网页后退怎么实现
- ASP.NET+C#下的一个BUG,不知道大家怎么解决,如果碰到了,真是倒霉,希望高人指点如何做?100送
- 想通过时间把表中的数据再增加一遍,只是时间变动,帮忙看一下哪个地方有问题呢??
- 请问为什么使用VS2005+WebService+AJAX在返回数据集的时候无法在客户端得到数据集字段的内容?
<head runat="server">
<title>测试</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function GetTest2()
{
createXMLHttpRequest();
var url= "test2.aspx";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=showResult;
xmlHttp.send(null);
}
function showResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("test2Div).innerHTML=xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center" id ="test2Div">
</div>
</form>
</body>
</html>//没有经过测试,自已试一下吧
//ajaxtest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="Share_AjaxTest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function GetTest2()
{
createXMLHttpRequest();
var id = document.getElementById("Text1").value;
var url= "ajaxtest2.aspx?id=" + id;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=showResult;
xmlHttp.send(null);
}
function showResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var Req = xmlHttp.responseText;
//取<form>和</form>中间的内容
var re=new RegExp(/(<form)([\s\S]+?)(>)([\s\S]+?)(<\/form>)/);
if(re.test(Req))
Req=RegExp.$4; document.getElementById("test2Div").innerHTML=Req;
}
}
}
</script> </head>
<body>
<form id="form1" runat="server">
<div>
传递参数 :<input id="Text1" type="text" value="0" />
<input id="Button1" type="button" value="button" onclick="GetTest2()" />
<div id="test2Div" style="width: 280px; height: 199px; position:absolute; left: 194px; top: 82px;border:1px solid #afafaf;">
</div>
</div>
</form>
</body>
</html>
//要显示的网页
//ajaxtest2.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest2.aspx.cs" Inherits="Share_AjaxTest2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head><body>
<form id="form2" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>//ajaxtest2.aspx.csusing System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Share_AjaxTest2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"] == null)
TextBox1.Text = "没有任何值传入";
else
TextBox1.Text = "传入了值:" + Request["id"].ToString();
}
}