Search code examples
asp.net-mvccomboboxobout

obout mvc combobox selected Index changed event not working


I have this MVC control this is my control

@Html.Obout(new Obout.Mvc.ComboBox.ComboBox("Country")
                        {
                            SelectedIndex = 0,
                            ShowSelectedImage = true,                                
                            ClientSideEvents = new ComboBoxClientSideEvents()
                            {
                                OnSelectedIndexChanged = "checkalert"
                            },

                         OnSelectedIndexChanged="checkalert",
                            ID = "Country1",
                            FolderStyle = "~/Content/Obout/ComboBox/styles/plain",
                            FilterType = Obout.Mvc.ComboBox.ComboBoxFilterType.Contains,
                            Width = 150,
                            Height = 200,
                            MenuWidth = 640
                        })

and this is my js function:

function checkalert() {
        debugger;
        alert(" change");
     return '1';
    }

I have an error that

Uncaught ReferenceError: checkalert is not defined

I need a checkalert() function triggered when selected index changed


Solution

  • From the documentation of obout it says that the function would have two input paramters i.e sender and selectedIndex, according to that your function definitions should look like:

    function checkalert(sender, selectedIndex) {
        debugger;
        alert(" change");
     return '1';
    }
    

    And also if you have script after the razor code in view, then you need to put the JavaScript code on top of view.

    You can see the working example with code provided on Obout site here.

    and also remove the other SelectedIndexChanged event which is defined after the ClientSideEvents setter as you need just client side event, that would cause errors as well.

    Hope it helps you resolve your issue.