比如有个数据库表,是存放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();"> <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> |
这里的关闭X按钮,调用javascript的脚本,等阵再说
然后当然要加scriptmanager控件了,如下
<asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="~/InboxService.asmx" /> </Services> </asp:ScriptManager> |
这里调用了我们刚才写的webservice
文章来源于领测软件测试网 https://www.ltesting.net/