Dialog Box in Asp.net

Source: Internet
Author: User

CompileProgramSometimes we want a dialog box to pop up when the program is running, giving you some prompts, especially the prompts for incorrect operations and confirmation of important information modification.

There are many examples of the application pop-up dialog box in Asp.net. I will summarize the two ways I have learned and applied during this period so that I can check them at any time:

(1) Prompt dialog box: This is a mode dialog box with only the "OK" button. This type of dialog box is relatively simple. Write the following in the area where you need to prompt:CodeYou can:

Response. Write ("<SCRIPT> alert ('content prompted on the dialog box ') </SCRIPT> ");

Note: This prompt does not seem to be useful in any part of the program. In the last case, the trail found that the statement was executed, but no dialog box was displayed. I did not find the cause, it may be related to Javascript execution, but I don't know much about it. If anyone knows this, please let me know. Thank you.

(2) confirmation dialog box: it is a mode dialog box with the "OK" button and "cancel" button. This dialog box is very important in some scenarios. It can be used in two ways.

In this dialog box, there are two ways to add: the two methods I use are implemented by adding properties to the button, because when I apply, A confirmation prompt is displayed after you click a button.

In the page_load () event, add the following attributes to the button for confirmation:

Button. Attributes. Add ("onclick", "Return getconfirm ();");

Open the. ascx file corresponding to this page, switch to HTML, and add the following code:

<SCRIPT>
Function getconfirm ()
{
If (confirm ("do you want to perform this operation? ") = True)
Return true;
Else
Return false;
}
</SCRIPT>

The second method is: In the page_load () event, add the attribute to the button that you want to display the confirmation prompt:

Button. Attributes. Add ("onclick", "Return confirm ('do you want to perform this operation? ');");

In fact, the two methods have the same principle. Relatively speaking, the second method is simpler.

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.