Pass data to button click event

7 posts, 0 answers
  1. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 03 Nov 2014 Link to this post

    Is there a way to pass additional data the button's click event? I need to pass information from the data item that the button is on (ListView template) to the function handling the click event.

    Thanks!
  2. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 04 Nov 2014 in reply to Cool Breeze Link to this post

    I misspoke earlier, the button is not inside a template for a list view. It is just on inside a loop that is creating a row for each record. I need to pass information about the current record through the click event. Thanks!
  3. Kendo UI is VS 2017 Ready
  4. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 05 Nov 2014 Link to this post

    Hello Joe,

    Please check this forum thread for details and a working sample. In your case, you should render the data in the respective data attribute. 

    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 05 Nov 2014 in reply to Petyo Link to this post

    Very nice. Thanks!
  6. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 05 Nov 2014 in reply to Cool Breeze Link to this post

    Hmm this is not working for me. My application is not a mobile application and I notice that the link you sent is for mobile...

    It just renders a button that has a link inside of it (underlined text) that I can't even click (event never gets fired). Mouse pointer changes to a cursor when hovering over the "button". Unable to click.

    Is there a way to pass additional data through razor syntax using your fluent API?

    @(Html.Kendo().Button()
    .Name("trackPackageButton_" + rowIndex)
    .Content("Track Package")
    .HtmlAttributes(new {type="button"})
    .Events(events => events.Click("trackPackage"))                               
    )

    Thanks!




  7. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 05 Nov 2014 in reply to Cool Breeze Link to this post

    Here is the code that doesn't work (from your example):

    <a data-role="button" id="buttonTrackPackage" data-click="trackPackage" data-trackingNumber="@order.TrackingNumber" class="k-primary">Track Package</a>
  8. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 07 Nov 2014 Link to this post

    Hi Joe,

    Generally, custom data cannot be passed as an argument to Kendo UI event handlers:

    http://docs.telerik.com/kendo-ui/basics/events-and-methods#event-handler-argument

    You need to store the custom data somewhere and retrieve it from inside the handler, depending on your preferences.

    Regards,
    Dimo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready