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

Command Args and CommandName from button..

8 Answers 902 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Juzzer
Top achievements
Rank 2
Juzzer asked on 22 Apr 2008, 04:29 PM
Hello!

I have just upgraded my toolbar from the old version to the new prometheus  (release) build and the syntax has totally changed and I can't work out how to get what I was working again.

My new tool bar has buttons as follows..

  <telerik:RadToolBarButton CommandName="if" Text="if" CommandArgument="condition" /> 
  <telerik:RadToolBarButton CommandName="then" Text="then" CommandArgument="condition" /> 
  <telerik:RadToolBarButton CommandName="else" Text="else" CommandArgument="condition" /> 

when someone clicks one I need to get at the commandName and Command Argument in the code behind.
Previously I did this:

string defaultText = e.Button.CommandName;  
string commandArg = e.Button.CommandArgument; 

in the onclick of the of the toolbar event, now there is no onClick, just an onButtonClick, so I have tried using this, but I can't work out how to get at the commandArgument or CommandName.

Please could you give me some sample code?
Thanks

B

8 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 23 Apr 2008, 06:53 AM
Hi Juzzer,

The RadToolBarButtonClick event passes a reference to a RadToolBarItem. We took that decision because  there are two items that can raise the button click event - RadToolBarButton and RadToolBarSplitButton. Apparently that did not take the best decision and we will improve this for the first service pack of the RadControls for ASP.NET Ajax.

Currently the proper way to identify the command name of the item is:
    protected void ToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
    {
        lblInfo.Text = string.Format("Item that initiated the postback was: {0}", e.Item.Text);
        if (e.Item is RadToolBarButton)
        {
            RadToolBarButton button = e.Item as RadToolBarButton;
            lblInfo.Text = string.Format("Item that initiated the postback was: {0}; its command name is: {1}", e.Item.Text, button.CommandName);
        }
        if (e.Item is RadToolBarSplitButton)
        {
            RadToolBarSplitButton splitButton = e.Item as RadToolBarSplitButton;
            lblInfo.Text = string.Format("Item that initiated the postback was: {0}; its command name is: {1}", e.Item.Text, splitButton.CommandName);
        }
    }

I hope this helps.

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Juzzer
Top achievements
Rank 2
answered on 23 Apr 2008, 08:20 AM
Thank you!  That works!

From what you said, am I correct in thinking that in the new release the syntax will change again and I will have to rewrite it?
0
Erjan Gavalji
Telerik team
answered on 23 Apr 2008, 08:49 AM
Hi Juzzer,

The change will involve changing the type of the e.Item from RadToolBarItem to IRadToolBarButton. This way no casts will be needed to get the values of the common button properties and the event handler code will be much simpler.

The code I sent you below will not be broken though, because the item will again be either a RadToolBarButton or a RadToolBarButton.

Cheers,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Val
Top achievements
Rank 1
answered on 03 Aug 2008, 12:56 AM
Has this change been implemented in Version: 2008.2 723?
0
Atanas Korchev
Telerik team
answered on 04 Aug 2008, 03:58 PM
Hello Val,

We postponed the implementation. It should be a fact in the SP1 release which is due at the end of August.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Val
Top achievements
Rank 1
answered on 08 Sep 2008, 11:45 AM
Any update on this fix?

I couldn't find it in the last SP released at the end of August.
0
Atanas Korchev
Telerik team
answered on 08 Sep 2008, 01:00 PM
Hi Val,

After further discussions we decided that changing the type of e.Item will introduce a breaking change in the API of RadToolBar. As we don't want to break existing customers' applications we decided not to introduce this change. Please accept our sincere apologies for misleading you.

Regards,
Atanas Korchev,
the Telerik dev team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Val
Top achievements
Rank 1
answered on 08 Sep 2008, 06:53 PM
No problem, it's just an inconvenience that requires a nasty hack to go around it. It will be nice though to keep in mind this issue for the future releases. Maybe you'll find an opportunity to add it as a non-breaking feature.
Tags
ToolBar
Asked by
Juzzer
Top achievements
Rank 2
Answers by
Erjan Gavalji
Telerik team
Juzzer
Top achievements
Rank 2
Val
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or