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

Best Method For Sending RadConfirm Response To CodeBehind

1 Answer 292 Views
Window
This is a migrated thread and some comments may be shown as answers.
Stacey Haslag
Top achievements
Rank 1
Stacey Haslag asked on 16 Jun 2010, 01:45 PM
I would like to have a radconfirm message on my aspx page, and depending on the answer, would like to do some server-side code.
I have found many, many different forums with multiple solutions for how to implement this logic. I could probably piece something together from what I have found, but I was curious as to the Best practices. I have never really had to communicate between client side and server side like this, so I really don't know what advantages/disadvantages there are to various methods. Would someone be able to "wrap it all up" for me in once post?

My requirements are as follows:
Situation One:
I have a Linkbutton to "Clear". When the user clicks this, I pop up a radConfirm asking them if they are sure. If they answer No, then I do nothing more. If they answer Yes, then I need to run some server-side code. I thought in this situation I would have my "CallBack" function from the radconfirm check the yes/no answer, and if yes, then call some server-side code, otherwise do nothing.   Does this sound like a logical method? Best way to call some server-side code from this javascript callback function?

Situation Two:
I have a "Clear" linkbutton inside of a repeater. This linkbutton has a CommandArgument bound to an ID, and I am using a CommandName; when clicked, I "delete" based on the specific ID. Simple enough. Now they want to add a "confirm" prompt to this process, and I would like to use radConfirm for this.  I would thing the process I have identified above would be okay, but how would I pass my desired bound ID to my callback function - can I just pass this into the parameter of the callback function?

Thanks for the help!
Stacey

1 Answer, 1 is accepted

Sort by
0
Stacey Haslag
Top achievements
Rank 1
answered on 16 Jun 2010, 05:09 PM
I have found a solution. I am not sure if this is the "best" way to handle my scenarios, but they seemed pretty staightforward to me. If someone has a suggestion they think is a better solution than what I came up with, please reply.


This is my aspx code, Javascript code, and code-behind:
<asp:LinkButton ID="lbtnClearAllSignatures" runat="server" Text="Clear All Signatures" OnClientClick="radconfirm('Are you sure you want to clear all signatures?', confirmClearAllCallBack, 400, 100, null, 'Clear All Signatures Confirmation'); return false;"></asp:LinkButton>  
   

<%

--this linkbutton is inside a repeater--%>
<

 

asp:LinkButton ID="lbtnClearSignature" runat="server" Text="Clear Signature"

 

 

    OnClientClick='<%# "ConfirmClearSingleSignature(" + ((int)Eval("SignatureId")) + ");" %>'>

 

</

 

asp:LinkButton>

 

 
<script type="text/javascript">  
    //<![CDATA[  
 
    //Rad Confirm Call Back Function for Clearing All Signatures  
    function confirmClearAllCallBack(arg) {  
        if (arg != null) {                          
            //If user confirms they want to clear all signatures, call server side method  
            if (arg == true) {  
                var ajaxManager = $find("<%= rdAjaxManager.ClientID %>");  
                if (ajaxManager != null) {  
                    ajaxManager.ajaxRequest("ClearAll");  
                    return false;  
                }  
            }  
            //If user cancels the clear all signatures, then simply return  
            else if (arg == false) {  
                return false;  
            }                          
        }  
    }  
 
    //Wrapper Confirmation Function For Single Clear Signature  
    function ConfirmClearSingleSignature(id) {  
      
        //Rad Confirm Call Back function for Clear Single Signature  
        function confirmClearSingleCallBack(arg) {  
            if (arg != null) {  
 
                //If user confirms they want to clear this signature, call server side method  
                if (arg == true) {  
                    var ajaxManager = $find("<%= rdAjaxManager.ClientID %>");  
                    if (ajaxManager != null) {  
                        ajaxManager.ajaxRequest(id.toString());  
                        return false;  
                    }  
                }  
                //If user cancels the clear signature, then simply return  
                else if (arg == false) {  
                    return false;  
                }  
            }  
        }  
 
        radconfirm('Are you sure you want to clear this signature?', confirmClearSingleCallBack, 400, 100, id, 'Clear Single Signature Confirmation');  
    }  
 
//]]>                                                                           
</script>  
 
 
//Event Handler for Rad Ajax Manager...Called When Rad Ajax Handler "ajaxRequest" event is invoked  
//from javascript code on the client  
public void rdAjaxManager_OnAjaxRequest(object sender, AjaxRequestEventArgs e)  
{  
    //If the argument parses to an integer, then the request is to clear just that single signature  
    //Otherwise the request is to clear all signatures  
 
    Nullable<int> signatureId = DataConversion.ToNullableInteger(e.Argument);  
    if (signatureId != null)  
        ClearSingleSignature(signatureId);  
    else 
        ClearAllSignatures();  

I am using the RadAjaxManager to call server-side code from Javascript. My RadAjaxManager event will determine, based on the event argument, what processing needs to be done.

The lbtnClearAllSignatures linkbutton simply calls the radConfirm. Inside this RadConfirmCallback function, I call my server-side method using the RadAjaxManager.

The lbtnClearSignature linkbutton was the tricky one. This is inside a repeater, and if confirmed, I need to clear based on a specific ID. So I call a "wrapper" javascript function, passing to it the ID I need. Inside this "wrapper" function, I call the radConfirm...etc.

As I stated previously, not sure if this is the "best" solution for how to call a server-side function from Javascript...and how to pass a value from javascript to server-side...but it worked for me.


Tags
Window
Asked by
Stacey Haslag
Top achievements
Rank 1
Answers by
Stacey Haslag
Top achievements
Rank 1
Share this question
or