Multiple Event Handlers

6 posts, 1 answers
  1. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 01 Apr 2015 Link to this post

    I am trying to have two javascript methods that get called when the change event on a DropDownList is raised.  If I set it up like this:

    @(Html.Kendo().DropDownListFor(m => m)
    ...
    .Events(e => e.Change("Method1").Change("Method2"))
    )

    Then only Method2 is called.  I can work around this a little bit by creating a third function, but then if I need the "this" variable from the event it looks like I have to pass it as a parameter to Method1 and Method2.

    Is it possible to have multiple handlers registered for one event on a kendo control?
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 02 Apr 2015 Link to this post

    Hello Brian,

    Can this issue be related to this known problem? If so, note it has been verified and fixed shortly after our Q1 2015 release, and we apologize for the inconvenience it caused you. The fix is included in the latest internal build of the product, which is available for download from your Telerik account's > DevCraft Ultimate > UI for ASP.NET MVC product downloads section.

    Please migrate to the new version and let us know whether this helps.

    Kind regards,
    Sebastian
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 02 Apr 2015 in reply to Sebastian Link to this post

    Sebastian,

    Thank you for your reply.  I don't think my situation is the same as that bug.  If I register one event handler for the change event, it works.  If I register two event handlers for the change event, only the second one is called.

    Thanks,
    Brian
  4. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3725 posts

    Posted 06 Apr 2015 Link to this post

    Hello Brian,

    The Fluent API of the wrappers is designed to override previous setting when same method is called. In this case, the sacond Change call will override the previous one. This behavior is expected and the only to accomplish your goal is to either use 3rd function or wire the events manually using JavaScript.

    Regards,
    Georgi Krustev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Attila
    Attila avatar
    18 posts
    Member since:
    Oct 2016

    Posted 30 Sep Link to this post

    Hi!

    I have a grid with 2 ClientTemplate columns. Each has different html input tag, so I need 2 different DataBound event handlers. is it possible? I have 2 different javascripts for uploading a file and of course 2 different action in my controller.

    The columns look like this:

    .Columns(columns =>
              {
                  columns.Template(@<text></text>).ClientTemplate("<input type='file' id='fileUpload' name='fileUpload' />");
                  columns.Template(@<text></text>).ClientTemplate("<input type='file' id='szamlaUpload' name='szamlaUpload' />");
              })

     

    I guess it's not possible to use in this case a .Event(e=>e.DataBound()) property of the grid, because it only allows 1 event handler. How can I use 2 different file upload in different columns?

    Thanks

  6. Tsvetina
    Admin
    Tsvetina avatar
    2102 posts

    Posted 03 Oct Link to this post

    Hi Attila,

    You cannot add two event handlers for the DataBound event using the Fluent API but you should not need to. I would suggest opening a new thread and explaining your scenario in more detail. You should be able to handle the logic related to Upload widgets in a single DataBound event handler.

    Additionally, note that it is not advisable to use ids in Kendo UI item/column templates. This results in rendering multiple elements with the same ID, which is invalid HTML and could lead to unexpected behavior. If you need the id attribute to access the uploads via JavaScript/jQuery, you can replace them with a class name specific to the upload inputs.

    Regards,
    Tsvetina
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top