ASP. NET uses ajax to implement pop-up window alarm prompts, mail arrival example

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.