C#+JS简单实现 定时轮询数据表 以及时弹出消息提示窗口(转)
2012-06-11 15:32
1066 查看
实现思路:
框架主页 + 弹出的消息显示页面
框架主页内 通过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();
}
}
}
}
}
http://www.cnblogs.com/wuhen/articles/1410872.html
框架主页 + 弹出的消息显示页面
框架主页内 通过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();
}
}
}
}
}
http://www.cnblogs.com/wuhen/articles/1410872.html
相关文章推荐
- C#+JS简单实现 定时轮询数据表 以及时弹出消息提示窗口
- C#+JS简单实现 定时轮询数据表 以及时弹出消息提示窗口
- C#+JS简单实现 定时轮询数据表 以及时弹出消息提示窗口
- JS实现简单的右下角弹出提示窗口完整实例
- JS实现点击某张图片弹出上传图片窗口以及限制图片格式和大小
- 利用js实现遮罩以及弹出可移动登录窗口
- Popupwin结合Timer实现定时弹出消息提示
- 利用JS弹出层实现简单的动态提示“正在加载中,请稍等...”
- js实现浏览器右下角弹出提示信息窗口,几秒后自动关闭
- js实现遮罩以及弹出可移动登录窗口
- JS实时弹出新消息提示框并有提示音响起的实现代码
- js弹出窗口简单实现代码
- JavaEE day03 使用JS完成简单的数据校验、完成图片轮播效果、完成页面定时弹出广告、完成表单校验
- JS实时弹出新消息提示框并有提示音响起的实现代码
- MSN弹出式消息提示窗口的JS实现
- js定时读取消息,并弹出动画效果的提示信息
- 利用js实现遮罩以及弹出可移动登录窗口
- 定时弹出消息窗口的实现
- 利用js实现遮罩以及弹出可移动登录窗口
- js弹框 父窗口弹出子窗口 以及 JS实现弹出层效果