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

Conditional server-side processing

4 Answers 135 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
topry
Top achievements
Rank 1
topry asked on 17 Dec 2008, 09:52 PM
When a specific button on the toolbar is pressed, I am using radprompt to solicit input from the user.
If they press OK, I want to retrieve the input text and pass it along to the server side code and if they cancel, do nothing.

I have everything working with the exception of being able to conditionally execute the server code based upon the user input.

Within the onclientbuttonclicked function I use .get_item().get_text to validate which button was pressed and then invoke radprompt, which displays and returns the input to the callback function but it also invokes my server-side code within the toolbar's _ButtonClick event. How can I make the _ButtonClick event conditional for this one button? (there are several buttons on the button bar, some conditional to user input, most are not).

 

function toolbarButtonClicked(sender, args) {  
    if (args.get_item().get_text() == "Close")  
        radprompt("Enter the resolution or press CANCEL if you do NOT want to CLOSE this ticket.", promptCallBackFn, 330, 110, sender, "Resolution", null);  
        return false;  
    }  
 
    function promptCallBackFn(arg) {  
    if (arg==null)  
        //do nothing  
    else   
        //execute server-side code in _ButtonClick event  
 
    } 

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 18 Dec 2008, 01:57 PM
Hello there,

I suggest you subscribe to OnClientButtonClicking instead of OnClientButtonClicked, because in its handler you can prevent the server-side click using eventArgs.set_cancel(true) method.

Best wishes,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
topry
Top achievements
Rank 1
answered on 18 Dec 2008, 02:56 PM
Thank you for the reply.
It would appear that using that event (OnClientButtonClicking) would require that I always invoke eventArgs.set_cancel(true) (since its an asynch/non-blocking function) and then within the callback of radPrompt, invoke the server side click event if the user pressed the OK button in radPrompt.

I can get an instance of the toolbarButton object via args.get_item() and invoke the button.click() event within the radprompt callback, however the issue Im having is if the user presses the close button (x) on the radprompt dialog, the callback is not called and I am unable to reset the toolbarbutton object.

Then there is the question of the 'best' method to return the user's input from radprompt to the server side. Currently, I am setting the returned text into a TextBox control on the page - quite a kludge. Obviously, my knowledge of jscript is still limited - so any suggestions would be appreciated.
var toolbarButton; Object;  
 
    function toolbarButtonClicking(sender, args) {  
        //check button name  
        if (args.get_item().get_text() == "Close") {  
            //to prevent re-entrancy, we will check the toolbarButton object  
            if (toolbarButton == null) {  
                args.set_cancel(true)  
                toolbarButton = args.get_item()  
                //prompt for resolution (non-blocking call)  
                radprompt("Enter the resolution or press CANCEL if you do NOT want to CLOSE this ticket.", promptCallBackFn, 330, 110, sender, "Resolution", null);  
            }  
            else  
                //reset our object to indicate the current cycle is complete  
                toolbarButton = null;  
        }  
        return false;  
    }  
 
    function promptCallBackFn(arg) {  
        if (arg != null) {  
            //set return value to a text control that has no border  
            var oArea = document.getElementById("txtReturnValue")  
            if (arg) oArea.value = arg 
            //invoke click for serverside processing  
            toolbarButton.click()  
            //clear the text control after server processing  
            oArea.value = "";  
        }  
        else  
            toolbarButton = null;  
    } 


0
Accepted
Yana
Telerik team
answered on 22 Dec 2008, 09:00 AM
Hi again,

When you close the window with (x) button, no event is fired, so the simplest solution to this problem is just to set VisibleTitlebar property of RadWindowManager to false, and in this way this button will not appear.

I suggest you return the user's input to the server by setting it to the button value like this:

toolbarButton.get_toolBar().trackChanges();  
toolbarButton.set_value(arg);  
toolbarButton.get_toolBar().commitChanges();  
toolbarButton.click()    
 
and then you can get it in the button click event handler:

e.Item.Value; 

Hope this helps.

Kind regards,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
topry
Top achievements
Rank 1
answered on 22 Dec 2008, 02:05 PM
Thank you very much, that does exactly what I need.

Regards,

Tim
Tags
ToolBar
Asked by
topry
Top achievements
Rank 1
Answers by
Yana
Telerik team
topry
Top achievements
Rank 1
Share this question
or