比如有个数据库表,是存放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; } } |
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="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> </asp:UpdateProgress> |
然后当然要加scriptmanager控件了,如下
<asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="~/InboxService.asmx" /> </Services> </asp:ScriptManager> |
这里调用了我们刚才写的webservice