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

首頁 > 編程 > .NET > 正文

ASP.NET 2.0中實現彈窗報警提示

2024-07-10 13:12:25
字體:
來源:轉載
供稿:網友

在 web應用中,比如oa中,經常要用到一些提示,比如email到達了,就做個象msn那樣的提示框,彈出給用戶提示,然后再關閉。在asp.net 2.0的ajax中,這個現在不難做到了,剛好看到老外的一篇文章,講解到,下面小結

比如有個數據庫表,是存放email的,當數據庫表中的email一有的時候,就提示用戶,首先簡單寫一個webservice如下

以下為引用的內容:
[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調用webserice,要加上[scriptservice]

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

以下為引用的內容:
<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=http://chinaz.com/program/.net/"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>

這里的關閉x按鈕,調用javascript的腳本,等陣再說

然后當然要加scriptmanager控件了,如下

以下為引用的內容:

 <asp:scriptmanager id="scriptmanager1" runat="server">
            <services>
                <asp:servicereference path="~/inboxservice.asmx" />
            </services>
        </asp:scriptmanager>

這里調用了我們剛才寫的webservice

之后是寫script了

以下為引用的內容:
<script type="text/javascript">
            var numberofemails_original= 0;
           
            var app = sys.application;
            app.add_init(applicationinithandler);
           
            function applicationinithandler(sender, args) {
                inboxservice.getlatestnumberofemails(oncurrentnumberofemailsready);
      }

首先,默認的當然是0封郵件了,有變量來存放當前郵件數量,之后是在ajax中的初始化事件中調用webserice的方法了,并且回調oncurrentnumberofemailsready方法,

以下為引用的內容:
     function oncurrentnumberofemailsready(result, usercontext, methodname) {
                numberofemails_original= result;
                // start checking
                startchecking();
            }

oncurrentnumberofemailsready方法將webservice調用的結果(當前狀態下有多少封信result)返回給變量,然后調用sartchecking()方法

      function startchecking() {
          inboxservice.getlatestnumberofemails(onlastestnumberofemailsready);
      }

startchecking方法,繼續回調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);
            }

這個方法,用當前郵件數-原來郵件數,就得出新增了多少封郵件了,再將結果賦值給顯示區域的modalbody,并且記得把當前郵件數量的,變量更新哦(numberofemails_original= numberofemails_new;)

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

以下為引用的內容:

            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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀安县| 六盘水市| 凉山| 水富县| 平定县| 广宗县| 朝阳市| 黄平县| 固原市| 岳普湖县| 新干县| 嵩明县| 乌鲁木齐县| 凌源市| 新巴尔虎右旗| 成武县| 沂源县| 浦城县| 云南省| 泸州市| 如东县| 留坝县| 冀州市| 新竹县| 曲阜市| 大安市| 历史| 蒙山县| 福建省| 策勒县| 玉树县| 苍梧县| 左云县| 平湖市| 和林格尔县| 龙泉市| 左贡县| 长兴县| 温州市| 扎赉特旗| 济阳县|