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

Widget object compare equals or not

1 Answer 8 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Veteran
Iron
Chris asked on 12 Jan 2018, 06:53 AM

HI

I have a question about widget object comparison : 

There have FirstButton and SecondButton in the view those share the same event handler (FirstButton_Click),
How can I tell the e.sender is equals to which ? 

Is the code correct or not ? if not how to do ? 

View

  @(Html.Kendo().Button()
    .Name("FirstButton")
    .Content("First")
    .Events(events => events.Click("class1.FirstButton_Click"))
    .HtmlAttributes(new { @type = "button" }))
   
  @(Html.Kendo().Button()
    .Name("SecondButton")
    .Content("Second")
    .Events(events => events.Click("class1.FirstButton_Click"))
    .HtmlAttributes(new { @type = "button" }))

Javascript

    FirstButton_Click: function(e)
    {
      // Click
      var FirstButton = $("#FirstButton").data("kendoButton"), SecondButton = $("#SecondButton").data("kendoButton");
      var FirstButton2 = $("#FirstButton").data("kendoButton");
      //
      if (e.sender == FirstButton)
        alert("The sender is FirstButton");
      if (e.sender == SecondButton)
        alert("The sender is SecondButton");


Best regards

Chris

 

 

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 16 Jan 2018, 07:31 AM
Hi Chris,

You can check the buttons ids and compare them like this:
if (e.sender.element[0].id == "FirstButton")
  alert("The sender is FirstButton");
if (e.sender.element[0].id == "SecondButton")
  alert("The sender is SecondButton");


Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Veteran
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or