I was wondering if anyone can provide advice here. Using MVC ASP.NET. I have a htmlhelper ddl

      @Html.DropDownListFor(m => m.ddlStartTime, new SelectList(Model.StartTimes, "Text", "Value", ViewBag.selected), new { data_test = "true", @Class = "form-control", onchange = "SubmitDayViewer(this.id)" })

Then I have a AJAX json request which goes and gets my data and returns a partial view along with some other json string data.

    function SubmitDayViewer(pId) {
        var obj1 = { dateValue: $('#dteTester').val(), timeValue: $('#ddlStartTime').val(), callerID: pId };
            type: "POST",
            url: '@Url.Action("_ADayRoomViewerPartial", "Common")',
            data: obj1,
            datatype: "json",
            success: function (data) {
                  $("#ddlStartTime").select2("val", data.DDLTimeValue);

The problem I can't overcome is preventing the @Html.DropDownListFor onChange event firing once I change the selected value. So I end up in an infinite loop. I need to devise a way to only fire the event when user changes the actual ddl. manually not when other controls on the page update and as a consequence need to change the selected value dynamically without firing the event. So basically fire onChange on some occasions not all.

Related posts

Recent Viewed