Conditional server-side processing

5 posts, 1 answers
  1. topry
    topry avatar
    32 posts
    Member since:
    Oct 2008

    Posted 17 Dec 2008 Link to this post

    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  
     
        } 
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 18 Dec 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. topry
    topry avatar
    32 posts
    Member since:
    Oct 2008

    Posted 18 Dec 2008 Link to this post

    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;  
        } 


  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 22 Dec 2008 Link to this post

    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.
  6. topry
    topry avatar
    32 posts
    Member since:
    Oct 2008

    Posted 22 Dec 2008 Link to this post

    Thank you very much, that does exactly what I need.

    Regards,

    Tim
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017