国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET 2.0中實(shí)現(xiàn)彈窗報(bào)警提示_.Net教程

2024-07-10 12:50:06
字體:
供稿:網(wǎng)友

推薦:ASP.NET十分有用的頁面間傳值方法
一、目前在ASP.NET中頁面?zhèn)髦倒灿羞@么幾種方式:1、表單提交 <form action= "target.aspx" method = "post" name = "form1"> <input name = "

在 web應(yīng)用中,比如OA中,經(jīng)常要用到一些提示,比如EMAIL到達(dá)了,就做個(gè)象MSN那樣的提示框,彈出給用戶提示,然后再關(guān)閉。在asp.net 2.0的ajax中,這個(gè)現(xiàn)在不難做到了,剛好看到老外的一篇文章,講解到,下面小結(jié)

比如有個(gè)數(shù)據(jù)庫表,是存放EMAIL的,當(dāng)數(shù)據(jù)庫表中的EMAIL一有的時(shí)候,就提示用戶,首先簡單寫一個(gè)WEBSERVICE如下

以下為引用的內(nèi)容:
[ScriptService]
public class InboxService : System.Web.Services.WebService
{
[WebMethod]
public int GetLatestNumberOfEmails()
{
int numberOfEmails = 0;
using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings[0].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("GetLatestNumberOfEmails", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
numberOfEmails = (int)cmd.ExecuteScalar();
}
}
return numberOfEmails;
}
}

這里要注意要在客戶端通過AJAX調(diào)用WEBSERICE,要加上[ScriptService]

2 在default.aspx中,首先加入一個(gè)updateprogress控件,如下

以下為引用的內(nèi)容:
<asp:UpdateProgress DynamicLayout="False" ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div id="modal" class="modal">
<div class="modalTop">
<div class="modalTitle">My Inbox</div>
<span style="CURSOR: hand" onclick="javascript:HidePopup();">
<img alt="Hide Popup" src="App_Themes/Default/images/close_vista.gif" border="0" />
</span>
</div>
<div class="modalBody">
You received <strong><span id="modalBody"></span></strong>&nbsp; Email(s).
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>

這里的關(guān)閉X按鈕,調(diào)用javascript的腳本,等陣再說

然后當(dāng)然要加scriptmanager控件了,如下

以下為引用的內(nèi)容:

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/InboxService.asmx" />
</Services>
</asp:ScriptManager>

這里調(diào)用了我們剛才寫的webservice

之后是寫script了

以下為引用的內(nèi)容:
<script type="text/javascript">
var numberOfEmails_original= 0;

var app = Sys.Application;
app.add_init(applicationInitHandler);

function applicationInitHandler(sender, args) {
InboxService.GetLatestNumberOfEmails(OnCurrentNumberOfEmailsReady);
}

首先,默認(rèn)的當(dāng)然是0封郵件了,有變量來存放當(dāng)前郵件數(shù)量,之后是在ajax中的初始化事件中調(diào)用webserice的方法了,并且回調(diào)OnCurrentNumberOfEmailsReady方法,

以下為引用的內(nèi)容:
function OnCurrentNumberOfEmailsReady(result, userContext, methodName) {
numberOfEmails_original= result;
// Start Checking
StartChecking();
}

OnCurrentNumberOfEmailsReady方法將WEBSERVICE調(diào)用的結(jié)果(當(dāng)前狀態(tài)下有多少封信RESULT)返回給變量,然后調(diào)用sartchecking()方法

function StartChecking() {
InboxService.GetLatestNumberOfEmails(OnLastestNumberOfEmailsReady);
}

startchecking方法,繼續(xù)回調(diào)OnLastestNumberOfEmailsReady方法

function OnLastestNumberOfEmailsReady(result, userContext, methodName) {
var numberOfEmails_new= result;
if (numberOfEmails_new > numberOfEmails_original) {
ShowPopup();
$get("modalBody").innerHTML= numberOfEmails_new - numberOfEmails_original;

// Update the count here
numberOfEmails_original= numberOfEmails_new;
}
// Start checking again
window.setTimeout(StartChecking, 10000);
}

這個(gè)方法,用當(dāng)前郵件數(shù)-原來郵件數(shù),就得出新增了多少封郵件了,再將結(jié)果賦值給顯示區(qū)域的modalbody,并且記得把當(dāng)前郵件數(shù)量的,變量更新哦(numberOfEmails_original= numberOfEmails_new;)

然后再用setimeout來設(shè)置每隔10000毫秒檢查一次了

以下為引用的內(nèi)容:

function ShowPopup() {
$get("UpdateProgress1").style.visibility= "visible";
$get("UpdateProgress1").style.display= "block";
}
function HidePopup() {
$get("UpdateProgress1").style.visibility= "hidden";
$get("UpdateProgress1").style.display= "none";
}
</script>

分享:ASP.NET生成靜態(tài)網(wǎng)頁的方法
環(huán)境:Microsoft .NET Framework SDK v1.1OS:Windows Server 2003 中文版ASP.Net生成靜態(tài)HTML頁,在Asp中實(shí)現(xiàn)的生成靜態(tài)頁用到的FileSystemObject對象,在.Net中涉及此類操作的是System.IO

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 湖北省| 永城市| 商洛市| 南丹县| 福州市| 元氏县| 云浮市| 延吉市| 温州市| 阳江市| 囊谦县| 永昌县| 囊谦县| 志丹县| 遵化市| 德阳市| 金阳县| 武宣县| 新蔡县| 景德镇市| 防城港市| 苍梧县| 绥芬河市| 江都市| 贡山| 博兴县| 凤台县| 武夷山市| 大埔区| 寿宁县| 方城县| 会泽县| 陇西县| 连州市| 咸宁市| 肇庆市| 雷州市| 麻阳| 西平县| 英超| 开平市|