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

Toolbar Javascript Confirm and Autopostback

4 Answers 214 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 21 Apr 2008, 01:43 PM
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?

4 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 22 Apr 2008, 12:48 PM
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
0
Don
Top achievements
Rank 1
answered on 30 Apr 2008, 02:28 PM
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.
0
Don
Top achievements
Rank 1
answered on 30 Apr 2008, 03:27 PM

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)
{

....
}
}
 

0
Erjan Gavalji
Telerik team
answered on 30 Apr 2008, 03:48 PM
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
Tags
ToolBar
Asked by
Don
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
Don
Top achievements
Rank 1
Share this question
or