后台页面一直打开在那里不动。如果有人在前台页面注册用户,后台页面就自动弹出一个提示,说有新人注册。想做到这样的效果,代码怎么写?谢谢。
解决方案 »
- .net程序员求职
- 支持.net网站的QQ第三方登录,有用过的朋友们共享一下,谢谢鸟
- ASP.NET部署后访问出错,是权限问题?
- 100分急求asp.net 2.0 TreeView 分角色/用户 显示不同节点
- 请问怎样设置CheckBoxList的某一个Item的Text颜色?
- 报表打印问题 急,急,急
- 写的程序有点问题,请大家帮忙测试一下看看是什么问题呢,谢谢,新的一年顺便送200分给大家啦,呵呵
- 关于HyperLink控件的问题
- SqlCommand如何通过传参数的方式插入null?微软准备怎么解决?加急...
- 在vs.net的IDE环境中如何更改在页面上添加文字时自动给文字添加字体的样式???
- log4net的问题,无法写入日志,只写入了header和footer
- 如何得到本页控件的问题
{
#region
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
#endregion
}
/// 是否异步请求
/// </summary>
private bool IsAynx
{
get
{
return Request["isaynx"] != null ? true : false;
}
}/// <summary>
/// 查询条件
/// </summary>
private string Query
{
get
{
return Request["qry"] != null ? return Request.QueryString["qry"].ToString() : "";
}
}……protected void Page_Load(object sender, EventArgs e)
{
if (IsAynx)
{
if (Query != "")
{
//在这里进行后端逻辑处理 访问数据库等
//和传统CS代码写法相同
……
getInfo(returnValue);
}
}
}……/// <summary>
/// 返回查询结果
/// </summary>
/// <param name="Msg">查询结果</param>
private void getInfo(string Msg)
{
string returnValue = string.Format("<Message>{0}</Message>", Server.UrlEncode(Msg)); Response.ContentType = "text/xml";
Response.AppendHeader("Cache-Control", "no-cache");
Response.Write(returnValue);
Response.Flush();
Response.End();
}
前端代码这么处理<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>TestPage</title>
<script language="javascript" type="text/javascript">
var xmlHttp;
var str = "aabbcc";
function createXMLHttp()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function doSearch()
{
if(document.getElementById("txt") != null)
{
str = document.getElementById("txt").value;
window.setInterval("Start()", 1000);
}
}
function Start()
{
if(str != "")
{
createXMLHttp();
var url = "Default9.aspx?qry=" + escape(str) + "&isaynx=1&t=" + new Date().getTime();
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = handleCallBack;
xmlHttp.send(null);
}
}
function handleCallBack()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
ShowMessage(xmlHttp.responseXML);
}
}
}
function ShowMessage(Val)
{
if(Val.getElementsByTagName("Message")[0] != null)
{
var s = Val.getElementsByTagName("Message")[0].firstChild.data;
alert(s);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="width:100%" align="left">
<asp:TextBox ID="txt" runat="server" Width="100%"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:100%" align="left">
<input type="button" value="Begin" onclick="doSearch();" />
</td>
</tr>
</table>
</form>
</body>
</html>
当时自己做着玩儿的页面,也是1秒钟刷新一次,看看是不是有点价值吧