网上关于PopupWin的使用方法有很多了,可以参考ASP.NET中Popup控件的使用方法。
PopupWin的下载地址和英文原文可以访问以下地址:http://www.codeproject.com/KB/custom-controls/asppopup.aspx。
关于无刷新弹出,只需添加Updatepanle中。
如要定时弹出,只需用两个Updatepanle,一个放置Time控件,设置时限进行刷新。另一个放置PopupWin。
PopupWin在与asp.net Ajax框架配合使用时,会有以下问题:
1.如设置PopuWin的Visible为false,在程序中必要的地方再设为true的话,页面运行后,会报错,且没有效果。
2.如设置AutoShow属性为false,在程序中必要的地方再设为true的话,页面运行后,会报错,且没有效果。
3.如设置AutoShow属性为true,则页面一加载就运行了PopupWin控件,即页面一加载就有弹出提示。
为解决以上问题,可以加入javascript方法: window.onload = null。这样页面加载时即不弹出提示。
代码如下:
前台:
![]()
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Assembly="EeekSoft.Web.PopupWin" Namespace="EeekSoft.Web" TagPrefix="cc1" %>
<!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 id="Head1" runat="server">
<title>Test</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="sm"></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="10000" Enabled="true">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label runat="server" ID="lb2"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="lb"></asp:Label>
<cc1:popupwin id="pw" runat="server" style="left: 63px; top: 99px"
DragDrop="False" Height="109px"
Width="214px" AutoShow="true"> </cc1:popupwin>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<mce:script type="text/javascript"><!--
window.onload = null;//页面加载时不运行PopupWin
// --></mce:script>
后台:
![]()
Code
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 Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lb2.Text=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
protected void Timer1_Tick(object sender, EventArgs e)
{
pw.Title = "你有新的消息";
pw.Message = "123451";
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.UpdatePanel1.GetType(), "msg", "pwespopup_winLoad();", true);
this.lb.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
this.UpdatePanel1.Update();
}
}
如与数据库相连接,定时查询数据库,只需在Time事件中查询数据库。
但,如用户过多,超过50个用户同时在线,定时查询数据库则会因频繁连接数据库,造成数据库堵塞,导致系统崩溃,或导致系统速度变慢。
关于这一问题,研究中....