CONFIRM () under the HTMLButton control

xiaoxiao2021-03-06  105

Author: Unknown author please contact me speed I. Introduction

Most of the actions such as deletion in ASP.NET are prompted to add confirm ('') to pop up the message box, but whether the HTML control and WEB control use are the same?

Second, the method

A. System.Web.ui.WebControls.Button control

It's us like this now.

Add from Page_Load

This.button1.attributes.add ("onclick", "JavaScript: return ('ok')");

B, System.Web.ui.htmlControls.htmlinputButton control

To achieve the purpose .. Assume that the above operation is performed in the HTML control

This.button2.attributes.add ("onclick", "JavaScript: Return Confirm ('OK')");

Of course, you can also directly in HTML.

ID = "Button2" Type = "Button" onclick = "javascript: return confirm ('ok?')" value = "button" name = "button2" runat = "server"

Run again, first he will prompt;

Open HTML code at this time

can be seen

Input language = "JavaScript" onclick = "javascript: return ('ok') __dopostback ('Button2', '')" name = "button2" id = "button2" type = "button" value = "button"

It can be clearly seen that it is not just less;

To add it

IF (! CONFIRM ('ok')) {return};

Otherwise, it will never run its return event.

C, other controls

Try other controls now

Protected system.web.ui.webcontrols.imagebutton imagebutton1;

Protected system.web.ui.webcontrols.linkbutton linkbutton1;

Protected system.Web.ui.htmlcontrols.htmlinputButton reset1;

Protected system.web.ui.htmlcontrols.htmlinputbutton submit1;

Similarly, add code in Page_Load, running it normally..

Open html You can see .. How do they go to open a hair only has a ... There is only LinButton in the href property __dopostback (), not in the Click event, there will be no above, and the other controls are not used __dopostback ()

D, tip skill

In the DataGrid, you can use more easier methods to delete the message box for deletion as long as you add

Delete

Third, summary

By seeing the above, you should pay attention to the differences and differences of each control when you want to add Attribute, and add Attribute to treat it according to the characteristics of each control.

转载请注明原文地址:https://www.9cbs.com/read-101691.html

New Post(0)