日期:2010-04-21  浏览次数:20546 次

在 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>  Email(s).
            </div>
        </div>
    </ProgressTemplate>