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.