RadControls version |
RadAjax, RadToolbar, RadWindow |
.NET version |
2.0 |
Visual Studio version |
2005 |
programming language |
C# |
browser support |
all browsers supported by RadControls |
PROJECT DESCRIPTION Unlike the standard confim(), radconfirm() cannot block the execution of the thread (this is something that cannot be done with Javascript) and a CallBackFunction is needed.
The attached project demonstrates a real-life scenario where when clicking one of RadToolbar's buttons we want to ask a confirmation from the user before performing the postback. RadWindowManager and RadToolbar are wrapped in RadAjaxPanel to avoid full page's postback.
The implementation of such scenario is relatively simple - when the user clicks on the button, we need to make a check what button is clicked and if it is the one which requires confirmation - cancel the postback and call radconfirm().
Once the user confirms the postback, in the radconfirm's CallBackFunction we will use __doPostBack to send the information on the server:
<script type="text/javascript"> |
<%= RadToolbar1.ClientID %>.attachEvent("OnClientClick","Toolbar_ClientClick"); |
|
function Toolbar_ClientClick(sender, e) |
{ |
if (sender.CommandName == "Delete") |
{ |
radconfirm("Delete?", CallBackFn); |
return false; |
} |
else |
{ |
return true; |
} |
} |
|
function CallBackFn(arg) |
{ |
if(arg) |
{ |
__doPostBack("<%= RadToolbar1.UniqueID %>", "onclick#Delete"); |
} |
} |
</script> |
in __doPostBack we are provide the following arguments:
- The UniqueID of the RadToolbar - this will allow us to reference the toolbar even if a MasterPage is used
- The RadToolBar command that we want to be executed.
And in the codebehind:
protected void RadToolbar1_OnClick(object sender, Telerik.WebControls.RadToolbarClickEventArgs e) |
{ |
Message.Text = "You clicked " + e.Button.CommandName + " " + DateTime.Now.ToString("hh:mm:ss"); |
} |