Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My code is

ASP.NET
<div class="col-md-2" id="dvabc"  runat="server">
<asp:DropDownList runat="server" AutoPostBack="true" ID="ddlabc" CssClass="form-control input-sm" OnSelectedIndexChanged="ddlStateMain_SelectedIndexChanged">
</asp:DropDownList>
</div>

<asp:TextBox runat="server" ID="txtSearch" placeholder="FPS" CssClass="form-control input-sm" />
 <div class="col-md-1">
               <asp:Button ID="btnView" runat="server" Text="View"
                                CausesValidation="true" class="btn btn-primary" OnClick="btnView_Click" />
                        </div>

JavaScript
<link href="jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.min.js" />
<script type="text/javascript" src="jquery-ui.min.js" />
<script type="text/javascript">

    $(document).ready(function () {

        SearchText();
    });

    function SearchText() {
        var abc = $('#<%=ddlabc.ClientID%>').text;
        var alloc = abc;
        var tehsil = "001";
        $('[id*=txtSearch]').autocomplete(
        {

            source: function (request, response) {

                $.ajax(
               {

                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: "frmPaymentByFPS.aspx/GetAutoSearchFPS",
                   data: "{'ddlAllocationOrderNo':'" + alloc + "','Tahsil':'" + tehsil + "','FairPriceShop':'" + extractLast(request.term) + "'}",

                   dataType: "json",
                   success: function (data) {

                       response(data.d);
                   },
                   error: function (result) {
                       alert("Error");
                   }
               });
            },
            focus: function () {
                // prevent value inserted on focus
                return false;
            },
            select: function (event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
        $("#txtSearch").bind("keydown", function (event) {
            if (event.keyCode === $.ui.keyCode.TAB &&
            $(this).data("autocomplete").menu.active) {
                event.preventDefault();
            }
        })
        function split(val) {
            return val.split(/,\s*/);
        }
        function extractLast(term) {
            return split(term).pop();
        }
    }

</script>

This java script is working for auto search.
When I Change index of ddlabc it does not work.
If I have button also and I click button then button and ddlabc index change both fired one by one.

In vs2010, it is working fine.

I have many drop down, text box and one button.
If click button it is fired but change selection of drop down does not fired.
If I change selection then i have to click button for selection change.
Any Event except button click event does not fire.


I found the thing is that prob from master page or bootstrap.
Posted
Updated 22-Dec-15 23:00pm
v13
Comments
Sreekanth Mothukuru 21-Dec-15 5:41am    
Do you have a server side event and a client side event for drop down ?!!
Member 7909353 22-Dec-15 2:09am    
I have only server side event for drop down.
Member 7909353 21-Dec-15 6:03am    
I do not want to have client side event for drop down

1 solution

You can fire OnSelectedIndexChanged event from client side script :

Add below codes inside : select: function (event, ui) {

JavaScript
var origEvent = event;
                       while (origEvent.originalEvent !== undefined)
                           origEvent = origEvent.originalEvent;
                       if ((origEvent.type == 'keydown') || (origEvent.type == 'click')) {
                          document.getElementById('<%=yourDropdownId.ClientID%>').onchange();
                           }

                       }


Good luck
 
Share this answer
 
v3
Comments
Member 7909353 21-Dec-15 6:48am    
Actually I have implement this java script for auto text search. It is working for auto search but index change event does not fire when i change selection.
Raje_ 21-Dec-15 7:30am    
Did you try adding above code? this code will fire onindex change when you click on searched items in drop down.
Member 7909353 21-Dec-15 7:41am    
I do not want to fire script on selection change.
Raje_ 21-Dec-15 8:06am    
I am sorry, I did not get what do you mean. If You don't want to fire onindex change event on drop down change then set AutoPostBack property to false. again i am just guessing here. Could you please be more specific about your requirements.
Member 7909353 22-Dec-15 2:10am    
I have server side event for drop down not client side.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900