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

Pass data to button click event

6 Answers 1767 Views
Button
This is a migrated thread and some comments may be shown as answers.
Cool Breeze
Top achievements
Rank 1
Cool Breeze asked on 04 Nov 2014, 05:28 AM
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!

6 Answers, 1 is accepted

Sort by
0
Cool Breeze
Top achievements
Rank 1
answered on 04 Nov 2014, 07:37 PM
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!
0
Petyo
Telerik team
answered on 05 Nov 2014, 10:09 AM
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!
 
0
Cool Breeze
Top achievements
Rank 1
answered on 05 Nov 2014, 06:59 PM
Very nice. Thanks!
0
Cool Breeze
Top achievements
Rank 1
answered on 05 Nov 2014, 07:14 PM
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!




0
Cool Breeze
Top achievements
Rank 1
answered on 05 Nov 2014, 07:16 PM
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>
0
Dimo
Telerik team
answered on 07 Nov 2014, 03:38 PM
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!
 
Tags
Button
Asked by
Cool Breeze
Top achievements
Rank 1
Answers by
Cool Breeze
Top achievements
Rank 1
Petyo
Telerik team
Dimo
Telerik team
Share this question
or