Sometimes I want to pop up a message in the client to prompt the user, not simply print a prompt message on the page, so that the page is not beautiful. The method of implementing the client pop-up message is simple, mainly binding events to buttons, or it can be implemented like MessageBox as in WIN FORM.
¹¹ With the button's Attribute property, the idea is to bind a Click event of the button with a JavaScript code.
Example: this.button1.attributes ["onclick"] = "JavaScript: Return Confirm ('Hello, Invoke from Load'";
The front part of this code is this.button1.attributes ["onclick] this refers to the click attribute of the button, and the rear section refers to the trigger processing of the Click event, using a JavaScript script.
2 The second method is similar to the first, as follows:
Webform1.aspx.cs: this.button1.attributes.add ("onclick", "javascript: return test ()");
Webform1.aspx:
?????????????????????????
???????????????????????????????????? script> // function test () {Alert ("Hello, Invoke from javascript ");
This method mainly binds the OnClick event to a JavaScript function written in the ASPX page.
3 said earlier, in Web Form, you can also be implemented using MessageBox as in Win Form. You need to import System.Window.Forms.dll names before Web Form Use MessageBox, then you can use it as used in Win Form. example:
Messagebox.show ("Hello", "Hello", MessageboxButtons.ok, MessageBoxicon.none, MessageBoxDefaultButton.Button1,
MessageBoxOptions.defaultdesktoponly);
Handling client messages using this way should pay special attention to the last parameter, otherwise this message box is not as expected to pop at the client, but in the server. "MessageBoxOptions.defaultDesktoponly" This parameter enables the message box to pop up, thus achieving the desired effect.
The .NET provides these very simple processing methods, which greatly improves development efficiency.