在 web应用中比如OA中经常要用到一些提示比如EMAIL到达了就做个象MSN那样的提示框弹出给用户提示然后再关闭在aspnet 的ajax中这个现在不难做到了刚好看到老外的一篇文章讲解到下面小结
比如有个数据库表是存放EMAIL的当数据库表中的EMAIL一有的时候就提示用户首先简单写一个WEBSERVICE如下
[ScriptService]
public class InboxService : SystemWebServicesWebService
{
[WebMethod]
public int GetLatestNumberOfEmails()
{
int numberOfEmails = ;
using (SqlConnection conn = new SqlConnection(WebConfigurationManagerConnectionStrings[]ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(GetLatestNumberOfEmails conn)) Chinaz_com
{
cmdCommandType = CommandTypeStoredProcedure;
connOpen();
numberOfEmails = (int)cmdExecuteScalar();
}
}
return numberOfEmails;
}
}
这里要注意要在客户端通过AJAX调用WEBSERICE要加上[ScriptService]
在defaultaspx中首先加入一个updateprogress控件如下
<asp:UpdateProgress DynamicLayout=False ID=UpdateProgress 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_vistagif border= />
</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=ScriptManager runat=server>
<Services>
<asp:ServiceReference Path=~/InboxServiceasmx />
</Services>
</asp:ScriptManager>
这里调用了我们刚才写的webservice
[] []