This is a migrated thread and some comments may be shown as answers.

RadConfirm and Delete?

4 Answers 340 Views
Window
This is a migrated thread and some comments may be shown as answers.
Evgeniy
Top achievements
Rank 1
Evgeniy asked on 05 Feb 2009, 09:58 AM
Hi all!

Please help me! I have following element on aspx page:
 <asp:button id="btnDelete" runat="server" OnClick="btnDelete_Click" OnClientClick="radconfirm('Are you sure you want to delete this listing?', confirmCallBackFn) " text="Delete" />

and I have RadWindowManager element
<telerik:RadWindowManager ID="windowManager" runat="server" Skin="Outlook"
        <ConfirmTemplate> 
            <div class="windowpopup radconfirm">    
                <div class="dialogtext"> {1} </div>       
                    <div> 
                        <onclick="$find('{0}').callBack(true);" class="radwindowbutton" href="javascript:void(0);" > 
                            <span class="outerspan"
                                <span class="innerspan">Yes, I’m sure</span> 
                            </span> 
                        </a> 
                        <onclick="$find('{0}').callBack(false);" class="radwindowbutton" href="javascript:void(0);"
                            <span class="outerspan"
                                <span class="innerspan">No, don’t delete</span> 
                            </span> 
                        </a> 
                    </div> 
            </div> 
        </ConfirmTemplate> 
    </telerik:RadWindowManager> 

and javascript function

function confirmCallBackFn(arg)
{
    return arg;
}

If I click on button then show confirm dialog but and event OnClick="btnDelete_Click" run too. Also I don't clicked on Yes or No button in confirm dialog.
What should I do to wait until user click on Button Yes or No?

Thanks!


4 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 05 Feb 2009, 12:29 PM
Hi Evgeniy,

As noted in the documentation and in the demos, radconfirm, radprompt and radalert cannot block the execution's thread like the standard browser's popups can. That is why a callback function is needed for radconfirm and radprompt where you can continue executing a client-side code.
In general, in scenario like yours, you need to cancel the postback and then to call a client function that would call a server-side one.
For example you can use RadAjaxManager's ajaxRequestWithTarget - for your convenience I attached a small sample that shows this approach in action.

Regards,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Evgeniy
Top achievements
Rank 1
answered on 05 Feb 2009, 02:39 PM
Thank you very much!

I apollogize But it code do not work in my page. Perhaps it was my guilt, because I am not quite correctly pointed markup the aspx page.
So I have <asp:LinkButton> in the <asp:repeater> control
<asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound" OnItemCommand="rpt_ItemCommand" ...> 
  <ItemTemplate> 
    ... 
    <asp:LinkButton ID="btnDelete" runat="server" Text="Delete Listing" CssClass="btnDashboardLinkDelete" CommandName="DeleteListing" CommandArgument='<%#Eval("Id") %>' OnClientClick="confirmFn(this,'Are you sure you want to delete this listing?');return false;" ></asp:LinkButton> 
    ... 
   </ItemTemplate> 
</asp:Repeater> 
 

How can you see on click btnDelete will be run event rpt_ItemCommand. May be in it problem?

Some ideas?

Thanks!



0
Georgi Tunev
Telerik team
answered on 06 Feb 2009, 09:18 AM
Hi Evgeniy,

In case like this, the repeater will render a series of links - that is why the suggested approach will not work. Instead I suggest to check the following Code Library article that shows how to mimic the blocking of the confirm thread:
http://www.telerik.com/community/code-library/aspnet-ajax/window/block-the-execution-thread-with-radconfirm.aspx

your code should look something like this:
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager> 
     
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
 <script type="text/javascript"
  
        var oldConfirm = radconfirm;    
 
        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){}    
                        }    
                    }    
                }    
 
                oldConfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);  
            }    
            return false;    
        }   
            </script> 
 
    </telerik:RadCodeBlock> 
 
        <div><telerik:RadAjaxManager  runat="server" ID="ram"  > 
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="Repeater1"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="Label1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <asp:Label ID="Label1" runat="server"></asp:Label> 
        <br /> 
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="AccessDataSource1" OnItemCommand="Repeater1_ItemCommand"
                <ItemTemplate> 
                    <asp:LinkButton ID="btnDelete" runat="server" Text='<%#Eval("ProductName") %>' CssClass="btnDashboardLinkDelete" 
                        CommandName="DeleteListing" CommandArgument='<%#Eval("ProductName") %>' OnClientClick="radconfirm('Are you sure you want to delete this item?',event);return false;"></asp:LinkButton><br /> 
                </ItemTemplate> 
            </asp:Repeater> 
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Nwind.mdb" 
                SelectCommand="SELECT TOP 10 [ProductName] FROM [Alphabetical List of Products]"
            </asp:AccessDataSource> 
        </div> 
    </form> 


Greetings,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Evgeniy
Top achievements
Rank 1
answered on 06 Feb 2009, 09:56 AM
It work wonderful!!!

Thank you very much!
Tags
Window
Asked by
Evgeniy
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Evgeniy
Top achievements
Rank 1
Share this question
or