A prompt box is displayed in the Ajax environment.

Source: Internet
Author: User

In a common ASP. NET environment, the following code is frequently used to bring up a dialog box on a web form:


<Span style = "font-family: simsun; font-size: 18px;"> <span style = "font-family: simsun; font-size: 18px;"> response. write ("<script language = JavaScript> alert ('failed to delete the question! ') </SCRIPT> "); </span>

However, the above Code cannot be used in the Ajax environment; otherwise, an error is reported. Because it does not regard the data as a statement for execution and only serves as a string, how can a prompt box pop up in the Ajax environment?

You can use the registerclientscriptblock () method of the scriptmanager class of Ajax to implement the pop-up dialog box function. This class can directly register the dialog box to the web form page.


The API for this method is as follows:

Clientscriptmanager. registerclientscriptblock Method


The following is a demo to familiarize you with the usage of this method.


We encapsulate all the dialogs to be popped up in the Ajax environment into a class to facilitate future calls, such as the dialog box popped up in the page, in the Ajax environment, the pop-up dialog box of the button is encapsulated into a class and can be called later.

<Span style = "font-family: simsun; font-size: 18px; ">/// <summary> /// display the dialog box in the Ajax environment /// </Summary> public class ajaxcommond {/// <summary> /// in the ASP. in the. NET Ajax environment, A prompt dialog box is displayed for the button control. /// </Summary> /// <Param name = "button"> button control </param> /// <Param name = "Message "> message in the dialog box </param> Public void opendialogforbutton (Button button, string message) {scriptmanager. registerclientscriptblock (button, typeof (button), datetime. now. tostring (). replace (":", ""), // use the current time as the identifier "alert ('" + message + "')", true );} /// <summary> /// in ASP. in the. NET Ajax environment, A prompt dialog box is displayed for the Page Object. /// </Summary> /// <Param name = "button"> Page Object </param> /// <Param name = "Message "> message in the dialog box </param> Public void opendialogforpage (page, string message) {scriptmanager. registerclientscriptblock (page, typeof (PAGE), // The passed type datetime. now. tostring (). replace (":", ""), // use the current time as the identifier "alert ('" + message + "')", // The information to be displayed is true); }}</span>


With this public class, the Demo code for calling is as follows:

<Span style = "font-family: simsun; font-size: 18px;"> protected void button#click (Object sender, eventargs e) {ajaxcommond AC = new ajaxcommond (); // instantiate the public class ajaxcommond // The prompt dialog box in the Ajax environment is displayed. opendialogforbutton (button) sender, "data is saved successfully! ") ;}</Span>


Summary

Of course, implementing the pop-up dialog box in the Ajax environment is more than this method. It is better to have more exchanges and learn from each other.





A prompt box is displayed in the Ajax environment.

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.