On button click, confirm box gets open, but it does not trigger the "btnDelete_Click" event on clicking of OK button.
Below is the code:
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick="return radconfirm('Delete Item?');" OnClick="btnDelete_Click" />
Please suggest me, where I am getting mistacke.
I have also tried OnClientClick="return radconfirm('Delete Item?', event);"
but i am getting following error:
Object doesn't support this property or method
6 Answers, 1 is accepted
The radconfirm dialog cannot block the execution of the thread by Javascript. The workaround is described in the code library here.
Block the execution thread with radconfirm
-Shinu.
Hi Shinu,
Thanks for your reply, but this approach is not working when I am using RadAjaxManager on my page
please have a look on my code:
Default.Aspx
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanelNormal" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanelNormal" runat="server" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<script type="text/javascript">
//MAKE SURE THAT THE FOLLOWING SCRIPT IS PLACED AFTER THE RADWINDOWMANAGER DECLARATION
//Replace old radconfirm with a changed version.
var oldConfirm = radconfirm;
//TELERIK
//window.radconfirm = function(text, mozEvent)
//We will change the radconfirm function so it takes all the original radconfirm attributes
window.radconfirm = function(text, mozEvent, oWidth, oHeight, callerObj, oTitle)
{
var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
//Cancel the event
ev.cancelBubble = true;
ev.returnValue = false;
if (ev.stopPropagation) ev.stopPropagation();
if (ev.preventDefault) ev.preventDefault();
//Determine who is the caller
var callerObj = ev.srcElement ? ev.srcElement : ev.target;
//Call the original radconfirm and pass it all necessary parameters
if (callerObj)
{
//Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
var callBackFn = function (arg)
{
if (arg)
{
callerObj["onclick"] = "";
if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
else if (callerObj.tagName == "A") //We assume it is a link button!
{
try
{
eval(callerObj.href)
}
catch(e){}
}
}
}
//TELERIK
//oldConfirm(text, callBackFn, 300, 100, null, null);
//We will need to modify the oldconfirm as well
oldConfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
}
return false;
}
</script>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="btnDelete" runat="Server" OnClientClick="return radconfirm('Are you sure?', event, 400, 200,'','Custom title');"
Text="Delete Item" OnClick="btnDelete_Click" />
</asp:Panel>
</div>
</form>
Default.Aspx.cs
protected void btnDelete_Click(object sender, EventArgs e)
{
Response.Write("Postback from asp:Button initiated");
}
I slightly changed the above code and its working fine without master page, when I am trying to use it with master page, again its not triggering the event
please have a look below code:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanelNormal" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanelNormal" runat="server" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function showConfirm(button)
{
function callbackFn(arg)
{
if (arg)
{
//get a reference to the RadAjaxManager
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
//make the callback and pass the id of the button
ajaxManager.ajaxRequestWithTarget(button.id, '');
}
}
//call the confirmation dialog
radconfirm("are you sure you want to post?", callbackFn);
}
</script>
</telerik:RadCodeBlock>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="btnDelete" runat="Server" OnClientClick="showConfirm(this); return false;"
Text="Delete Item" OnClick="btnDelete_Click" />
</asp:Panel>
</asp:Content>
Default.aspx.cs
protected void btnDelete_Click(object sender, EventArgs e)
{
Response.Write("Postback from asp:Button initiated");
}
Please Note : My Requirement is : Using radconfirm with RadAjaxManager & Master Page
Thanks
Mukesh
(I tried to get the args.get_item().get_value() instead args.get_item().get_text()
but not luck
script
function
onClientConfirm(sender, args)
{
if
(args.get_item().get_text() ==
"Delete"
|| args.get_item().get_text() ==
"Confirm"
|| args.get_item().get_text() ==
"Cancel"
)
{
if
(!clickCalledAfterRadconfirm)
{
args.set_cancel(
true
);
lastClickedItem = args.get_item();
radconfirm(
"Are you sure to <b>"
+ args.get_item().get_text() +
"</b> this record?"
, confirmCallbackFunction);
}
}
function
confirmCallbackFunction(args) {
if
(args) {
clickCalledAfterRadconfirm =
true
;
lastClickedItem.click();
}
else
clickCalledAfterRadconfirm =
false
;
lastClickedItem =
null
;
}
aspx with the local resoruces
<
telerik:RadToolBar
ID
=
"toolbar"
runat
=
"server"
OnButtonClick
=
"toolbarClick"
OnClientButtonClicking
=
"onClientConfirm"
Skin
=
"WebBlue"
Width
=
"100%"
meta:resourceKey
=
"toolbarResource1"
>
<
Items
>
<
telerik:RadToolBarButton
runat
=
"server"
CommandName
=
"Cancel"
meta:resourceKey
=
"RadToolBarButtonResource1"
Text
=
"Cancel"
ToolTip
=
"Cancel current actions and clear all fileds."
Value
=
"Cancel"
Width
=
"100px"
>
</
telerik:RadToolBarButton
>
<
telerik:RadToolBarButton
runat
=
"server"
CommandName
=
"Add"
meta:resourceKey
=
"RadToolBarButtonResource2"
Text
=
"Add"
ToolTip
=
"Add new user to MultiRoute"
ValidationGroup
=
"Save"
Value
=
"Add"
Width
=
"100px"
>
</
telerik:RadToolBarButton
>
<
telerik:RadToolBarButton
runat
=
"server"
CommandName
=
"Delete"
meta:resourceKey
=
"RadToolBarButtonResource3"
Text
=
"Delete"
ToolTip
=
"Delete the selected user"
Value
=
"Delete"
Visible
=
"False"
Width
=
"100px"
>
</
telerik:RadToolBarButton
>
<
telerik:RadToolBarButton
runat
=
"server"
CommandName
=
"Save"
meta:resourceKey
=
"RadToolBarButtonResource4"
Text
=
"Save"
ToolTip
=
"Save changes in the selected user"
ValidationGroup
=
"Save"
Value
=
"Save"
Visible
=
"False"
Width
=
"100px"
>
</
telerik:RadToolBarButton
>
<
telerik:RadToolBarButton
runat
=
"server"
CommandName
=
"Reset"
meta:resourceKey
=
"RadToolBarButtonResource5"
Text
=
"Reset Password"
ToolTip
=
"Reset password to the selected user"
Value
=
"Reset"
Visible
=
"False"
Width
=
"100px"
>
</
telerik:RadToolBarButton
>
</
Items
>
<
CollapseAnimation
Duration
=
"200"
Type
=
"OutQuint"
/>
</
telerik:RadToolBar
>
I remove meta:resourceKey and work perfectly again. but I need to keep the meta resource to be able to translate the text.
any observation? I just create the local resources and no touch the Value property when I translated it.
I use RadControls for ASP.NET AJAX Q1 2010
Even I hammered the script function with an if with text in spanish no luck either
if
(args.get_item().get_text() ==
"Delete"
|| args.get_item().get_text() ==
"Confirm"
|| args.get_item().get_text() ==
"Cancel"
)
{
if
(!clickCalledAfterRadconfirm)
{
args.set_cancel(
true
);
lastClickedItem = args.get_item();
radconfirm(
"Are you sure to <b>"
+ args.get_item().get_text() +
"</b> this record?"
, confirmCallbackFunction);
}
}
if
(args.get_item().get_text() ==
"Borrar"
|| args.get_item().get_text() ==
"Confirmar"
|| args.get_item().get_text() ==
"Cancelar"
) {
if
(!clickCalledAfterRadconfirm) {
args.set_cancel(
true
);
lastClickedItem = args.get_item();
radconfirm(
"¿Está seguro de que quiere <b> "
+ args.get_item().get_text() +
" </ b> este récord?"
, confirmCallbackFunction);
}
}
Can you confirm there are no JavaScript errors on the page? It is possible that some special symbols (most probably quotation marks, apostrophes and backslashes) break the scripts on the page and hence a lot of JavaScript functionality fails. I would advise going through the resources used to see if this is the case, i.e. if removing such symbols (or escaping them) helps. I would also strongly advise that you test with the latest version of the controls, because for the three years that have passed since your version was released there have been a lot of improvements and fixes on all controls.
All the best,
Marin Bratanov
the Telerik team
I can live with the no accentuation for this. "Estás" means you are or are you depends in the context and Estas means these but for me es much worth to eliminate the accentuation that the meaning...I guess...
I just wonder why radalert works my accentuation and the radconfirm not.