Client Confirmation and AJAX in RadControls for asp.net (telerik).
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:
The OnClientClick should be changed a bit to work with AJAX:
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:
I hope you enjoyed this article, and it made your life a little bit easier.
If you have any question then feel free to ask us.
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 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>
<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>
I hope you enjoyed this article, and it made your life a little bit easier.
If you have any question then feel free to ask us.
No comments:
Post a Comment