Popupwin结合Timer实现定时弹出消息提示
?
目前開發(fā)的項目中需要實現(xiàn)到發(fā)送消息提醒的功能,在網(wǎng)上找到了這款仿MSN的消息控件,感覺它還是可以滿足我們使用要求的,就拿過來用了,現(xiàn)在把使用的過程及心得體會寫下來,供需要的人參考。
首先下載EeekSoft.Web.PopupWin.dll,將其添加到項目的引用中之后,然后在前臺添加代碼:
<%@ Register Assembly="EeekSoft.Web.PopupWin" Namespace="EeekSoft.Web" TagPrefix="cc1" %>就可以使用該控件了。
如果想要實現(xiàn)在打開的網(wǎng)頁中的定時異步刷新,則可以結(jié)合使用Asp.net控件Timer的UpdatePanel,分別將Timer和Popupwin放在一個UpdatePanel中,UpdateMode屬性設置為Conditional,這里簡單的介紹一下UpdatePanel的屬性,它共有兩個屬性值:
always:頁面上的任何控件的操作都會引起對UpdatePanel中的內(nèi)容的更新;
conditional:只有UpdatePanel中的控件的操作才會引起UpdatePanel中的內(nèi)容的更新。
這樣就大概能理解將UpdateMode屬性設為Conditional的用意了吧, 即不能讓頁面上任何一個對任何一個控件的操作都引起Timer的Popupwin的刷新。
前臺代碼如下:
1 <asp:ScriptManager runat="server" ID="sm"></asp:ScriptManager> 2 <div> 3 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" > 4 <ContentTemplate> 5 <asp:Timer ID="Timer" runat="server" ontick="Timer_Tick" Interval="6000" Enabled="true"> 6 </asp:Timer> 7 </ContentTemplate> 8 </asp:UpdatePanel> 9 <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" > 10 <ContentTemplate> 11 <cc1:popupwin id="pw" runat="server" style="left: 63px; top: 99px" ActionType="RaiseEvents" HideAfter="-1" ShowAfter="500" 12 ShowLink="true" AutoShow="true" Visible="true" OnLinkClicked="pw_LinkClick" /> 13 </ContentTemplate> 14 </asp:UpdatePanel> 15 </div>?后臺代碼如下:
protected void Timer_Tick(object sender, EventArgs e){ScriptManager.RegisterStartupScript(this.UpdatePanel2, this.UpdatePanel2.GetType(), "msg", "pwespopup_winLoad();", true);//讀取數(shù)據(jù)庫中未提醒信息,根據(jù)需要拼接成字符串賦值給popupwin的Message屬性 string msg = "<table boder='0' cellspacing='0' cellpadding='3' class='small'>";msg += "<tr><td align='center'><a href=\"javascript:ReadMsg('AllMsgs')\">您有" + unReadCount.ToString() + "條未讀提醒</a></td></tr>";foreach (DictionaryEntry de in ht){msg += "<tr><td><a href=\"javascript:ReadMsg('" + de.Key + "')\"><img alt='' src='" + htImg[de.Key] + "' />" +de.Key + "(" + de.Value + ")條</a><td><tr>"; }msg += "</table>"; pw.Message = msg;pw.Title = "消息提醒"; pw.ColorStyle = EeekSoft.Web.PopupColorStyle.Blue;pw.DragDrop = true;pw.Width = 200;pw.Height = 100 + ht.Count * 10;pw.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;this.UpdatePanel2.Update();} }protected void pw_LinkClick(object sender, EventArgs e){}?
?最后的效果圖如下:
?選中其中一行文本都可以執(zhí)行相應的前臺js腳本函數(shù)。
?
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/sophia-yun/archive/2012/09/02/2667251.html
總結(jié)
以上是生活随笔為你收集整理的Popupwin结合Timer实现定时弹出消息提示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Oracle UTL_FILE包操作
- 下一篇: css2.1中 firefox 与IE