Reputation: 148
I have the following code:
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="rlpMain">
<asp:ImageButton ID="ImageButton1" runat="server"
OnClientClick="return confirm('Are you sure?');" />
</telerik:RadAjaxPanel>
This code does not fire my code behind event which I have written in a .vb file.
Pls help me....
Upvotes: 2
Views: 2651
Reputation: 1614
One may need to provide a confirmation dialog to the users and initiate an AJAX request if accepted. Confirmation using standard post backs often looks like this:
<asp:ImageButton ID="ImageButton1" runat="server"
OnClientClick="return confirm('Are you sure?');" />
The OnClientClick should be changed a bit to work with AJAX:
<asp:ImageButton ID="ImageButton2" runat="server"
OnClientClick="if (!confirm('Are you sure?')) return false;" />
When the button is ajaxified by added the necessary AJAX setting to RadAjaxManager or when the button is placed within RadAjaxPanel control.
Alternatively, the OnRequestStart client-side event could be used to implement more complex logic. Here is a sample script:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function OnRequestStart(ajaxControl, eventArgs) {
var eventTarget = eventArgs.get_eventTarget();
if (eventTarget == "<%= ImageButton1.UniqueID %>") {
return confirm('Are you sure?');
}
else {
return false;
}
}
</script>
</telerik:RadCodeBlock>
Upvotes: 4
Reputation: 1010
If you want to stick with the RadControls, you can use a RadButton as an ImageButton as defined here:
http://www.telerik.com/help/aspnet-ajax/button-image-buttons.html
Create a button with the OnClientClicking attribute set to a function that calls a confirm (or radconfirm for sticking within telerik) below:
function ConfirmDeletion(sender, args) {
var ContinuePostBack = Function.createDelegate(sender, function (clickedOK) {
if (clickedOK) {
this.click();
}
});
var text = "Are you sure you wish to delete this attribute?";
radconfirm(text, ContinuePostBack, 300, 100, null, "Deletion");
args.set_cancel(true);
}
This will cancel the postback, but then click the button via the delegate ContinuePostBack if the user clicked OK. I have used this code a lot for prompting deletions.
Upvotes: 0