In web development, we often use some prompts. For example, if an email arrives, we will create a prompt box like MSN, pop up a prompt to the user, and then close it. In Asp.net 2.0's Ajax, This is not hard to do now. I just saw an article from a foreigner and explained it. The following is a summary.
For example, if there is a database table that stores emails, when there is an email in the database table, the user will be prompted. First, simply write a WebService as follows:
Reference content is as follows:
[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;
}
}
Note that you need to add [scriptservice] to the client to call webserice through Ajax.
2 In default. aspx, first add an updateprogress control, as shown below:
Reference content is as follows:
<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
</Span>
</Div>
<Div class = "modalbody">
You have Ed <strong> <span id = "modalbody"> </span> </strong> & nbsp; email (s ).
</Div>
</Div>
</Progresstemplate>
</ASP: updateprogress>
Close the X button here and call the Javascript script.
Then, add the scriptmanager control as follows:
Reference content is as follows:
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
<Services>
<Asp: servicereference Path = "~ /Inboxservice. asmx "/>
</Services>
</ASP: scriptmanager>
The WebService we just wrote is called here.
The script is written later.
Http://www.itwis.com/html/net/net20/list_21_2.html