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

RadConfirm on RadtreeView NodeClick

4 Answers 142 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Courouble Damien
Top achievements
Rank 1
Courouble Damien asked on 27 Aug 2009, 09:30 AM
Hi everybody !

As you can see in my post title I try to find a way to have a radconfirm (client side) when the user is selecting (clicking) a node of a radtreeview.

E.G > User is currently on a node called "Employee Example" on right panel I display some informations of the node using a query in database like name, surname ...of the employee the user can edit this and save by clicking a button save, but in case of the user change selecting node and don't push the save button I want to display a radconfirm saying " you've made some changes but you don't save if you continue all changes will be lost" and so the user will have choice to hit "Cancel" (so the right pane don't change) and if he hit "Ok"  then postback the right panel and display informations for the new selecting node.using query.

For the moment I use the standard confirm, i also store a value in a hiddenfield, the value of it change by clicking on "Ok" or on "Cancel" and after in code behind I check the value to see if it's need to do the query, or not depending of the user choice, but of course it do posback in any cases that's what I want to change !

I hope you'll understand my issue.

Thanks in advance for reading this

Regards,

Damien



4 Answers, 1 is accepted

Sort by
0
Mr. Plinko
Top achievements
Rank 1
answered on 31 Aug 2009, 09:04 PM

You can do throw an alert window when a user clicks on a node by using some Javascript and attaching it to a Client-Side event (eg OnClientNodeClicking)

<body> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1"  
        runat="server"
    </telerik:RadScriptManager> 
 
    <telerik:RadTreeView ID="RadTreeView1"  
        Runat="server" OnClientNodeClicked="OnClientNodeClicked"
        <Nodes> 
            <telerik:RadTreeNode runat="server"  
                Text="Root RadTreeNode1"
            </telerik:RadTreeNode> 
        </Nodes> 
    </telerik:RadTreeView> 
<script language="javascript"
 
 
    function OnClientNodeClicked() 
    var agree = confirm("you've made some changes but you don't save if you continue all changes will be lost"); 
if (agree) 
    return true ; 
else 
    return false ; 
</script> 
 
    </form> 
</body> 

Is that what you were asking?

0
Courouble Damien
Top achievements
Rank 1
answered on 01 Sep 2009, 08:02 AM
Yes, that's approximatly it ! I mean I would be great if I can use a Radconfirm component instead of alert, is it possible ?
0
Veselin Vasilev
Telerik team
answered on 01 Sep 2009, 03:42 PM
Hello Courouble Damien,

Please find attached a sample project.

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Courouble Damien
Top achievements
Rank 1
answered on 02 Sep 2009, 09:17 AM
Hi !!

I've test your project on mine : that's work perfectly, many thanks !
But there's one thing more I want to do : I want to add others parameters to the onclientnodeclicking for radconfirm text, title, width and height to be able to translate the confirm message.

I use this function

window.blockConfirm = 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) { }
                }
            }
        }
        if (window.parent == null) {
            radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
        }
        else {
            window.parent.radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
        }
    }
    return false;
}

on my project so i'm able to declare this on in onclientclicking event in behind code and give this functions some c# vars.
this one don't work on radmenu item clicking so I want to use the same way with your function : is it possible ?

Thanks for helping me !

Damien

Tags
TreeView
Asked by
Courouble Damien
Top achievements
Rank 1
Answers by
Mr. Plinko
Top achievements
Rank 1
Courouble Damien
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or