ASP. NET Programming implementation pop-up window warning prompt preface, in web applications, such as OA, often need to use some prompts, such as e-mail arrived, just make a prompt box like MSN, A prompt is displayed for the user and then closed. 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))
- {
- 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.
ASP. NET Programming implementation pop-up window alarm prompt 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();"﹥
- ﹤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﹥
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.
ASP. NET Programming implementation pop-up window alarm prompt: Script
Reference content is as follows:
- ﹤script type="text/javascript"﹥
- var numberOfEmails_original= 0;
-
- var app = Sys.Application;
- app.add_init(applicationInitHandler);
-
- function applicationInitHandler(sender, args) {
- InboxService.GetLatestNumberOfEmails(OnCurrentNumberOfEmailsReady);
- }
First of all, the default mail is of course 0. there are variables to store the current mail quantity. Then, the webserice method is called in the ajax initialization event and the OnCurrentNumberOfEmailsReady method is called back,
Reference content is as follows:
- FunctionOnCurrentNumberOfEmailsReady (result, userContext, methodName ){
- NumberOfEmails_original = result;
- // Start Checking
- StartChecking ();
- }
- OnCurrentNumberOfEmailsReady method returns the RESULT of the WEBSERVICE call to the variable, and then calls the sartchecking () method.
-
- FunctionStartChecking (){
- InboxService. GetLatestNumberOfEmails (OnLastestNumberOfEmailsReady );
- }
-
- Startchecking method, continue to call back the OnLastestNumberOfEmailsReady Method
-
- FunctionOnLastestNumberOfEmailsReady (result, userContext, methodName ){
- VarNumberOfEmails_new = result;
- If(NumberOfEmails_new> numberOfEmails_original ){
- ShowPopup ();
- $ Get ("ModalBody"). InnerHTML = numberOfEmails_new-numberOfEmails_original;
-
- // Update the count here
- NumberOfEmails_original = numberOfEmails_new;
- }
- // Start checking again
- Window. setTimeout (startcheck, 10000 );
- }
This method uses the current number of mails-the original number of mails to determine how many new mails are added. Then, assign the result to modalbody in the display area and remember to set the current number of mails, variable update: numberOfEmails_original = numberOfEmails_new ;)
Then we use setimeout to set the check interval to 10000 milliseconds.
Reference content is as follows:
- function ShowPopup() {
- $get("UpdateProgress1").style.visibility= "visible";
- $get("UpdateProgress1").style.display= "block";
- }
- function HidePopup() {
- $get("UpdateProgress1").style.visibility= "hidden";
- $get("UpdateProgress1").style.display= "none";
- }
- ﹤/script﹥
The information about the implementation of the pop-up window alarm prompt in ASP. NET programming will be introduced to you here, hoping to help you.
- Analysis of JavaScript insertion methods in ASP. NET
- Analysis of ASP. NET JavaScript and ole db Design network diary
- Code Analysis of Cookie deletion in ASP. NET
- Syntax analysis of nested If statements in ASP. NET Programming
- Analysis of Date and Time Processing in ASP. NET Programming