Command Args and CommandName from button..

9 posts, 0 answers
  1. Juzzer
    Juzzer avatar
    12 posts
    Member since:
    Sep 2007

    Posted 22 Apr 2008 Link to this post

    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

  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 23 Apr 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Juzzer
    Juzzer avatar
    12 posts
    Member since:
    Sep 2007

    Posted 23 Apr 2008 Link to this post

    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?
  5. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 23 Apr 2008 Link to this post

    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
  6. Val
    Val avatar
    18 posts
    Member since:
    Aug 2007

    Posted 02 Aug 2008 Link to this post

    Has this change been implemented in Version: 2008.2 723?
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 04 Aug 2008 Link to this post

    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.
  8. Val
    Val avatar
    18 posts
    Member since:
    Aug 2007

    Posted 08 Sep 2008 Link to this post

    Any update on this fix?

    I couldn't find it in the last SP released at the end of August.
  9. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 Sep 2008 Link to this post

    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.
  10. Val
    Val avatar
    18 posts
    Member since:
    Aug 2007

    Posted 08 Sep 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017