Edit this page

Hybrid ButtonGroup HtmlHelper Overview

The hybrid ButtonGroup HtmlHelper extension is a server-side wrapper for the hybrid Kendo UI ButtonGroup widget.

It allows you to configure the hybrid Kendo UI Button from server-side code.

Configuration

Below are listed the steps for you to follow when configuring the hybrid Kendo UI ButtonGroup for ASP.NET MVC.

  1. Create a new ASP.NET MVC 4 application. If you have installed the Telerik UI for ASP.NET MVC Visual Studio Extensions, create a Telerik UI for ASP.NET MVC application. If you decide not to use the Telerik UI for ASP.NET MVC Visual Studio Extensions, follow the steps from the introductory article to add Telerik UI for ASP.NET MVC to the application.

  2. Open HomeController.cs and modify the Index action method.

    Example
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
    
            return View();
        }
    
  3. Add a hybrid Kendo UI ButtonGroup to the Index view. Like most hybrid Kendo UI widgets, the ButtonGroup must be initialized within the hybrid View content.

    Example
    
           <% Html.Kendo().MobileView()
                    .Name("buttongroup-view")
                    .Title("Inbox")
                    .Content(() =>
                    {
                        %>
    
                        <%: Html.Kendo().MobileButtonGroup()
                                .Name("select-period")
                                .Items(items =>
                                {
                                    items.Add().Text("Month");
                                    items.Add().Text("Quarter");
                                    items.Add().Text("Year");
                                })
                                .Index(0)
                        %>
                        <%
                    })
                    .Render();
            %>
    
    
            @(Html.Kendo().MobileView()
                .Name("buttongroup-view")
                .Title("Inbox")
                .Content(
                    @<text>
    
                    @(Html.Kendo().MobileButtonGroup()
                        .Name("select-period")
                        .Items(items =>
                        {
                            items.Add().Text("Month");
                            items.Add().Text("Quarter");
                            items.Add().Text("Year");
                        })
                        .Index(0)
                    )
    
                </text>)
            )
    
  4. Initialize the mobile application.

    Example
    
            <%: Html.Kendo().MobileApplication()
                    .ServerNavigation(true)
            %>
    
    
            @(Html.Kendo().MobileApplication()
                .ServerNavigation(true)
            )
    
  5. Build and run the application.

Event Handling

You can subscribe to all hybrid ButtonGroup events.

By Handler Name

The following example demonstrates how to subscribe to events by a handler name.

Example

        <%: Html.Kendo().MobileButtonGroup()
                .Name("select-period")
                .Items(items =>
                {
                    items.Add().Text("Month");
                    items.Add().Text("Quarter");
                    items.Add().Text("Year");
                })
                .Index(0)
                .Events(events => events.Select("onSelect"))
        %>

        <script>
        function onSelect() {
            //Handle the select event
        }
        </script>

        @(Html.Kendo().MobileButtonGroup()
                .Name("select-period")
                .Items(items =>
                {
                    items.Add().Text("Month");
                    items.Add().Text("Quarter");
                    items.Add().Text("Year");
                })
                .Index(0)
                .Events(events => events.Select("onSelect"))
        )

        <script>
        function onSelect() {
            //Handle the select event
        }
        </script>

Reference

Instances

You can reference a hybrid ButtonGroup instance by using the code from the example below. Once a reference is established, use the hybrid ButtonGroup API to control its behavior.

Example
    @(Html.Kendo().MobileButtonGroup()
        .Name("select-period")
        .Items(items =>
        {
            items.Add().Text("Month");
            items.Add().Text("Quarter");
            items.Add().Text("Year");
        })
        .Index(0)
    )
    <script>
    $(function() {
        // Notice that the Name() of the buttongroup is used to get its client-side instance
        var buttongroup = $("#select-period").data("kendoMobileButtonGroup");
    });
    </script>

See Also