How to register second event handler for client's ButtonClicked?

6 posts, 0 answers
  1. Ferdinand
    Ferdinand avatar
    56 posts
    Member since:
    Jun 2008

    Posted 27 Jul 2010 Link to this post

    Hi,
    I would like to register a second event handler for the RadToolBar's client side event "OnClientButtonClicked". Is that somehow possible?
    The first event was registered by adding it to the toolbar's "OnClientButtonClicked" property.

    Best regards
    Ferdinand
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 27 Jul 2010 Link to this post

    Hello Ferdinand,

    I'm afraid that you can have only one handler for an event.

    Regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Jul 2010 Link to this post

    Hello,

    I am getting confused about why you are trying to add two event handlers for same event and also I am not sure about whether it is possible. Could you elaborate the scenario that you are trying?

    If you want to change the event handler to new handler from code behind, then you could try setting new name for OnClientButtonClicked.
    aspx:
    <telerik:RadToolBar OnClientButtonClicked="clicked1" ID="RadToolBar1" runat="server">
        <Items>
         . . .
        </Items>
    </telerik:RadToolBar>

    Code behind:
    protected void Button1_Click(object sender, EventArgs e)
    {
        RadToolBar1.OnClientButtonClicked = "clicked2"; // Change the handler
    }

    Client code:
    <script type="text/javascript">
        function clicked1(sender, args) {  // default handler
            alert("clicked1");
        }
        function clicked2(sender, args) {  // New handler
            alert("clicked2");
        }
    </script>


    -Shinu.
  5. Ferdinand
    Ferdinand avatar
    56 posts
    Member since:
    Jun 2008

    Posted 27 Jul 2010 Link to this post

    Hi and thanks for the answers.
    @Shinu: To my intentions: In my project every page has a toolbar. I wrote a UserControl that adds a button to the toolbar which calls a RadTooltip clientside. Some of my toolbars already have handlers for OnButtonClicked so that I have to attach another one for the event.

    @Yana: Sorry I have to disagree with you but actually I found a way to add a second handler to the toolbar's OnClientClicked. After some debugging I found the following way:
    function AddHandlerToToolbar(toolbarClientId) {
         var toolbar = $find(toolbarClientId);
         if (toolbar != null) {
             toolbar.add_buttonClicked(OnCsvButtonClicked);
         }
     }
    By using the function "add_buttonClicked" it is possible to add another handler to the event.

    Best regards
    Ferdinand
  6. Sébastien
    Sébastien avatar
    55 posts
    Member since:
    Jun 2010

    Posted 28 Jul 2010 Link to this post

    I'm intrigued because it is actually working, but why is it working and why do would you one two event handler for the same event???. Really confusing...
  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 30 Jul 2010 Link to this post

    Hello,

    Ferdinand: you are right about that - you can register more handlers for the same client event using client-side code (not in the aspx page). I'm sorry for my mistake.

    Sébastien: actually this is how javascript works - you can also attach two click events to a button.

    Best wishes,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017