ASP.NET利用ajax實現彈窗警示提示,郵件到達樣本

來源:互聯網
上載者:User

在web開發中,我們會經常用到一些提示,比如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)) Chinaz_com 
            {
                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();"> Www_Chinaz_com 
                 <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> 

這裡的關閉X按鈕,調用javascript的指令碼,等陣再說

然後當然要加scriptmanager控制項了,如下

以下為引用的內容:

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

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

之後是寫script了

http://www.itwis.com/html/net/net20/list_21_2.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.