实现思路:
框架主页 + 弹出的消息显示页面
框架主页内 通过js定时执行一隐藏按钮的click事件
其事件为查询消息表
如有新消息 则在框架页弹出消息提示窗口
消息提示窗口 定时自动关闭
其内有 已读 和 删除 及 链接 按钮
链接按钮 负责刷新框架面的iframe中的src
=====================
相关示例代码如下:
----------------
框架页面HTML部分
----------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="f_Test4.aspx.cs" Inherits="f_Test4" %><!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 language="javascript" type="text/javascript">
//定时执行按钮事件 查看是否有新的消息
function fn_BtnEventOnTime()
{
document.all.btnhid_RefMsg.click();
}
window.onload=function()
{
window.setInterval("fn_BtnEventOnTime()",20000);
}
function fn_OpenMsgWindow(varTestID)
{
var paraTestID =escape(varTestID);
window.open('f_MsgAlert.aspx?&TestIDPara='+paraTestID+'',"","dependent=no,location=no,height=100,width=200,left=0,top=600,");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>TestID</td>
<td>
<asp:TextBox ID="txt_TestID" runat="server"></asp:TextBox>
</td>
<td>TestNote</td>
<td>
<asp:TextBox ID="txt_TestNote" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<%--保存按钮 负责写入数据到数据库的f_Test表--%>
<asp:Button ID="btn_Save" runat="server" Text="保存" OnClick="btn_Save_Click" />
<br />
<input id="btnhid_RefMsg" type="button" value="隐藏按钮 刷新消息提示"
runat="server" onserverclick="btnhid_RefMsg_ServerClick"
style="display:none;" />
<br />
<%--消息窗口 链接 按钮 将显示页面在iframe中--%>
<iframe id="ShowPage" ></iframe>
</form>
</body>
</html>-------------------
框架页面.cs代码部分
-------------------
using 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 f_Test4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
} protected void btn_Save_Click(object sender, EventArgs e)
{
string strCommand1 = " INSERT INTO f_Test(TestID, TestNote , TestState) ";
strCommand1 += " VALUES( ";
strCommand1 += " " + this.txt_TestID.Text.Trim() + " ";
strCommand1 += " ,'" + this.txt_TestNote.Text.Trim() + "' ";
strCommand1 += " ,'0' ";//消息状态为0 表示为新消息 需提示
strCommand1 += " )";
DBClass db1 = new DBClass(); if (db1.RunNotSelectSqlCommand(strCommand1))
{
CommClass.DoAlert(this.Page, "新增 保存 成功");
}
else
{
CommClass.DoAlert(this.Page, "新增 保存 失败");
}
} protected void btnhid_RefMsg_ServerClick(object sender, EventArgs e)
{
string strCommand = " SELECT TOP 1 TestID FROM f_Test ";
strCommand += " WHERE TestState='0' ";
DBClass db = new DBClass();
DataSet ds = db.RunSelectGetDataSet(strCommand);
if (ds.Tables[0].Rows.Count > 0)
{
string strTestID = ds.Tables[0].Rows[0][0].ToString().Trim();
string strJS = "<script language='javascript' type='text/javascript'>";
strJS += " fn_OpenMsgWindow('" + strTestID + "'); ";
strJS += "</script>";
Page.RegisterStartupScript("winOpenJS", strJS);
}
}
}
--------------------------
弹出的消息显示页面HTML部分
--------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="f_MsgAlert.aspx.cs" Inherits="f_MsgAlert" %><!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 language="javascript">
<!--
function clock()
{
i=i-1
document.title="消息提示 "+i+"秒后关闭!";
if(i>0)
{
setTimeout("clock();",1000);
}
else
{
window.returnValue = '';
window.opener = null;
window.close();
}
}
var i=10
clock();
//-->
function openLink()
{
var pageURL = "f_Test1.aspx";
// window.opener.document.getElementById("txt_TestID").value = "abc";
window.opener.document.frames("ShowPage").window.location.href = pageURL;
window.returnValue = '';
window.opener = null;
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>TestID</td>
<td>
<asp:TextBox ID="txt_TestID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>TestNote</td>
<td>
<asp:TextBox ID="txt_TestNote" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<asp:Button ID="btn_Readed" runat="server" Text="已读" />
<asp:Button ID="btn_Link" runat="server" Text="链接" OnClientClick="openLink();" />
<asp:Button ID="btn_Delete" runat="server" Text="删除" />
</form>
</body>
</html>-----------------------------
弹出的消息显示页面.cs代码部分
-----------------------------
using 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 f_MsgAlert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(!string.IsNullOrEmpty(Request["TestIDPara"]))
{
string strCommand = " SELECT TOP 1 TestID ,TestNote FROM f_Test ";
strCommand += " WHERE TestID='" + Request["TestIDPara"].Trim() + "' ";
DBClass db = new DBClass();
DataSet ds = db.RunSelectGetDataSet(strCommand);
if (ds.Tables[0].Rows.Count > 0)
{
this.txt_TestID.Text = ds.Tables[0].Rows[0]["TestID"].ToString().Trim();
this.txt_TestNote.Text = ds.Tables[0].Rows[0]["TestNote"].ToString().Trim();
}
}
}
}
}
框架主页 + 弹出的消息显示页面
框架主页内 通过js定时执行一隐藏按钮的click事件
其事件为查询消息表
如有新消息 则在框架页弹出消息提示窗口
消息提示窗口 定时自动关闭
其内有 已读 和 删除 及 链接 按钮
链接按钮 负责刷新框架面的iframe中的src
=====================
相关示例代码如下:
----------------
框架页面HTML部分
----------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="f_Test4.aspx.cs" Inherits="f_Test4" %><!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 language="javascript" type="text/javascript">
//定时执行按钮事件 查看是否有新的消息
function fn_BtnEventOnTime()
{
document.all.btnhid_RefMsg.click();
}
window.onload=function()
{
window.setInterval("fn_BtnEventOnTime()",20000);
}
function fn_OpenMsgWindow(varTestID)
{
var paraTestID =escape(varTestID);
window.open('f_MsgAlert.aspx?&TestIDPara='+paraTestID+'',"","dependent=no,location=no,height=100,width=200,left=0,top=600,");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>TestID</td>
<td>
<asp:TextBox ID="txt_TestID" runat="server"></asp:TextBox>
</td>
<td>TestNote</td>
<td>
<asp:TextBox ID="txt_TestNote" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<%--保存按钮 负责写入数据到数据库的f_Test表--%>
<asp:Button ID="btn_Save" runat="server" Text="保存" OnClick="btn_Save_Click" />
<br />
<input id="btnhid_RefMsg" type="button" value="隐藏按钮 刷新消息提示"
runat="server" onserverclick="btnhid_RefMsg_ServerClick"
style="display:none;" />
<br />
<%--消息窗口 链接 按钮 将显示页面在iframe中--%>
<iframe id="ShowPage" ></iframe>
</form>
</body>
</html>-------------------
框架页面.cs代码部分
-------------------
using 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 f_Test4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
} protected void btn_Save_Click(object sender, EventArgs e)
{
string strCommand1 = " INSERT INTO f_Test(TestID, TestNote , TestState) ";
strCommand1 += " VALUES( ";
strCommand1 += " " + this.txt_TestID.Text.Trim() + " ";
strCommand1 += " ,'" + this.txt_TestNote.Text.Trim() + "' ";
strCommand1 += " ,'0' ";//消息状态为0 表示为新消息 需提示
strCommand1 += " )";
DBClass db1 = new DBClass(); if (db1.RunNotSelectSqlCommand(strCommand1))
{
CommClass.DoAlert(this.Page, "新增 保存 成功");
}
else
{
CommClass.DoAlert(this.Page, "新增 保存 失败");
}
} protected void btnhid_RefMsg_ServerClick(object sender, EventArgs e)
{
string strCommand = " SELECT TOP 1 TestID FROM f_Test ";
strCommand += " WHERE TestState='0' ";
DBClass db = new DBClass();
DataSet ds = db.RunSelectGetDataSet(strCommand);
if (ds.Tables[0].Rows.Count > 0)
{
string strTestID = ds.Tables[0].Rows[0][0].ToString().Trim();
string strJS = "<script language='javascript' type='text/javascript'>";
strJS += " fn_OpenMsgWindow('" + strTestID + "'); ";
strJS += "</script>";
Page.RegisterStartupScript("winOpenJS", strJS);
}
}
}
--------------------------
弹出的消息显示页面HTML部分
--------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="f_MsgAlert.aspx.cs" Inherits="f_MsgAlert" %><!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 language="javascript">
<!--
function clock()
{
i=i-1
document.title="消息提示 "+i+"秒后关闭!";
if(i>0)
{
setTimeout("clock();",1000);
}
else
{
window.returnValue = '';
window.opener = null;
window.close();
}
}
var i=10
clock();
//-->
function openLink()
{
var pageURL = "f_Test1.aspx";
// window.opener.document.getElementById("txt_TestID").value = "abc";
window.opener.document.frames("ShowPage").window.location.href = pageURL;
window.returnValue = '';
window.opener = null;
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>TestID</td>
<td>
<asp:TextBox ID="txt_TestID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>TestNote</td>
<td>
<asp:TextBox ID="txt_TestNote" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<asp:Button ID="btn_Readed" runat="server" Text="已读" />
<asp:Button ID="btn_Link" runat="server" Text="链接" OnClientClick="openLink();" />
<asp:Button ID="btn_Delete" runat="server" Text="删除" />
</form>
</body>
</html>-----------------------------
弹出的消息显示页面.cs代码部分
-----------------------------
using 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 f_MsgAlert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(!string.IsNullOrEmpty(Request["TestIDPara"]))
{
string strCommand = " SELECT TOP 1 TestID ,TestNote FROM f_Test ";
strCommand += " WHERE TestID='" + Request["TestIDPara"].Trim() + "' ";
DBClass db = new DBClass();
DataSet ds = db.RunSelectGetDataSet(strCommand);
if (ds.Tables[0].Rows.Count > 0)
{
this.txt_TestID.Text = ds.Tables[0].Rows[0]["TestID"].ToString().Trim();
this.txt_TestNote.Text = ds.Tables[0].Rows[0]["TestNote"].ToString().Trim();
}
}
}
}
}
解决方案 »
- 不同的会话如何避免产生重复的Session("Key")内容?
- 駁sp1234之[如果你必须开发交互式页面,ViewState越大可能意味着越有本事]一貼
- NET AJAX MS控件集中的UpdatePanel怎么获取控件集合?
- contentplaceholder中用了在table里的gridview,gridview会遮住sitemapnode?
- 请大家推荐一套最好的博客程序asp.net+mssql的
- 【asp.net】服务器上没有安装excel,怎么实现web客户端的excel数据导入数据库?
- 请问怎么样将数据类型转换为数据库中的自动编号类型?
- 如何在一个文本框取得焦点时就隐藏另一个表格行?
- vs2008 WEB设计
- 在datagrid中加入radiobutton后,如何通过点击单选按钮获取datagrid中的一条记录???
- 谁写过排行榜代码!人民币求排行榜代码(急要现成的)!
- Ajax
一般讲ajax的书上都会有说。
这里有个例子,我做的通知发布,你看看有没有用!
http://www.ibm.com/developerworks/cn/web/wa-lo-comet/非定时刷新的解决方案~