Toolbar Javascript Confirm and Autopostback

5 posts, 0 answers
  1. Don
    Don avatar
    22 posts
    Member since:
    Oct 2007

    Posted 21 Apr 2008 Link to this post

    Hi, grreetings, 
    I have a Rad toolbar with with 5-7 buttons. couple of buttons like new, print, help work only client side and the client side click event opens up rad windows. the rest of the buttons do some server side work. there is one button (Delete), that requires a Rad Comfirm dialog to come up and on confirmation (OK) the javascript should let the button do server side code, (if Cancel it should just stop and return. ).

    here is my Toolbar defination:

    <rad

    :RadToolbar ID="MainToolbar" runat="server" ButtonWidth="26px"

    style="margin-bottom: 0px" ononclick="MainToolbar_OnClick"

    AutoPostBack="True">

    attchment of the client Side event handler:

    window[userToolbar].attachEvent("OnClientClick","User_Toolbar_Click_Handler");

    here is my Client Siode Javascript function: 
    var returnValue;

    function User_Toolbar_Click_Handler(sender, e)
    {
    /// Toolbar Event handler of the user.aspx page.
        switch(sender.CommandName)
        {
            case 'New':
            window.radopen("DetailPages/UserDetails.aspx?isNew=true&userId=-1","PropertiesWindow");
            return false;
            break;
            case 'ImportUsers':
            doImportUsers();
            return false;
            break;
            case 'Delete':
            doDeleteUsers();
            return returnValue;

            break;
            default :
            radalert('Option not ready', '', 150,"Message");
            return false;
        }
        return false;
    }
    function doImportUsers()
    {
      radconfirm('Are you sure you want to import Users from the LDAP store?', importUsersCallBack, 330, 100); 

    function doDeleteUsers()
    {
      radconfirm('Are you sure you want to Delete User?', deleteCallBack, 330, 100);

       function deleteCallBack(arg)  
       {  
           returnValue = arg;
       } 


    Question: either it does the client side code or it does ther server side code. never both together. what else is required to get the toolbar to work as we need it to?

  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 22 Apr 2008 Link to this post

    Hi Don,

    Due to the specifics of the radconfirm function, this can be done by using some tweaks - when clicked, you should save the reference to the toolbar button in a variable, which EventClick method should be called in the deleteCallBack function.
    The doDeleteUsers function should check if the item was initialized so that it shoud either calls the radConfirm function (and return false) or should return true. Here is the sample:

    ...
    var globalClickedItem = null;
    function User_Toolbar_Click_Handler(sender, e)
    {
    ...
    case 'Delete':
            return doDeleteUsers(sender);
            break;
    ...
    }

    function doDeleteUsers(item)
    {
        if (globalClickedItem == null)
        {
            globalClickedItem = item;
            radconfirm('Are you sure you want to Delete User?', deleteCallBack, 330, 100);
            return false;
        }
        return true;
    }

    function deleteCallBack(arg)
    {
        if (arg)
        {
            globalClickedItem.EventClick({});
        }
        globalClickedItem = null;
    }

    I hope this helps.

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Don
    Don avatar
    22 posts
    Member since:
    Oct 2007

    Posted 30 Apr 2008 Link to this post

    Hi, thank you for this solution, it just works fine.
    However, we upgraded to the new AJAX controls. now its broken again. I cant get to the commandName or value of the toolbar button on the client side. the demos that I have, only find toolbar buttons by text? How would I change the code given by you to make it work in the new scenario.
  5. Don
    Don avatar
    22 posts
    Member since:
    Oct 2007

    Posted 30 Apr 2008 Link to this post

    Ok never mind my question, I figured out the answer: however let me know if this is good way. 
    one can get the selected value by using this clinet side api

    function

    User_Toolbar_Click_Handler(sender, e)

    {

    var selectedValue = e.get_item().get_value();
    switch(selectedValue)
    {

    ....
    }
    }
     

  6. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 30 Apr 2008 Link to this post

    Hi Don,

    Indeed, this is the correct approach. You can use also the get_commandName property method of RadToolBarButton and RadToolBarSplitButton.

    Best regards,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017