First look at a confirm introduction
Confirmbutton is a simple extender that catches clicks on a button (or any
Instance of a type derived from button) and displays a message to the user. If
The "OK" button is clicked, the button or link functions normally. If not,
Click is trapped and the button will not perform its default submit behavior;
Optionally, a client script is executed if the onclientcancel property is set.
This is useful for Delete links or anything else that requires confirmation from
The user.
Add ajaxcontroltoolkit. dll reference in the project
Code:
Code
< ASP: linkbutton ID = "Linkbutton" Runat = "Server" Onclick = "Button_click" > Click me </ ASP: linkbutton >
< Ajaxtoolkit: confirmbuttonextender ID = "Confirmbuttonextender1" Runat = "Server"
Targetcontrolid = "Linkbutton"
Confirmtext = "Are you sure you want to click the linkbutton? "
Onclientcancel = "Cancelclick" />
< BR />
< BR />
< ASP: button ID = "Button" Runat = "Server" Text = "Click me" Onclick = "Button_click" /> < BR />
< Ajaxtoolkit: confirmbuttonextender ID = "Confirmbuttonextender2" Runat = "Server"
Targetcontrolid = "Button"
Onclientcancel = "Cancelclick"
Displaymodalpopupid = "Modalpopupextender1" />
< BR />
< Ajaxtoolkit: modalpopupextender ID = "Modalpopupextender1" Runat = "Server" Targetcontrolid = "Button" Popupcontrolid = "Pnl" Okcontrolid = "Buttonok" Cancelcontrolid = "Buttoncancel" Backgroundcssclass = "Modalbackground" />
< ASP: Panel ID = "Pnl" Runat = "Server" Style = "Display: none; width: 200px; Background-color: White; border-width: 2px; border-color: black; border-style: solid; padding: 20px ;" >
Are you sure you want to click the button?
< BR /> < BR />
< Div Style = "Text-align: right ;" >
< ASP: button ID = "Buttonok" Runat = "Server" Text = "OK" />
< ASP: button ID = "Buttoncancel" Runat = "Server" Text = "Cancel" />
</ Div >
</ ASP: Panel >
Protected Void Button_click ( Object Sender, eventargs E)
{
Label1.text = " You clicked " + (Control) sender). ID + " At " + Datetime. Now. tolongtimestring () + " . " ;
}
Code < Script Type = ' Text/JavaScript ' >
Function Cancelclick (){
VaR Label = $ Get ( ' Maincontent_label1 ' );
Label. innerhtml = ' You hit cancel in the confirm dialog on ' + ( New Date (). localeformat ( " T " ) + ' . ' ;
}
< / SCRIPT>
Several attributes of confirmbuttonextender:
Targetcontrolid-The ID of the button or link for this
Extender to operate on.
Confirmtext-The text to show when you want to confirm
Click. (Note: HTML entities can be used here (ex :"
"
New-line ))
Onclientcancel-The client-side script that executes when
The cancel button is clicked in the confirm dialog.
Confirmonformsubmit-True if the confirm dialog shocould
Wait until just before the form submits to display. This is useful when ASP. NET
Validators are in use and the confirm shocould be shown only after all validators
Pass.
Displaymodalpopupid-Optionally specifies the ID of
Modalpopup control to use for displaying the confirmation dialog (instead
Window. Confirm). When using displaymodalpopupid, the following conditions must
Be met:
- The modalpopup must be configured to work against the same targetcontrolid
As the confirmbutton (and shocould work properly if the confirmbutton is
Disabled ).
- The modalpopup must specify okcontrolid and/or cancelcontrolid to identify
The buttons corresponding to window. Confirm's OK/cancel buttons.
- The modalpopup must not specify onokscript or oncancelscript.
Linkbutton dialog box
Button confirmation dialog box