How to associate javascript event handler with Ajax Control Toolkit drop-down list when changing text field

I need a combo box for an ASP.NET project, so I decided to use the Ajax Control Toolkit combo box ( http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx ).

I don’t want to use postback because I don’t want the page to reload, but I need to know when the text in the text box has changed, so I can go to the server to save the new list item.

I'm curious how I bind an onchange or onblur event to the input field that this combobox uses.

This is my asp.net page:

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<cc1:ComboBox ID="PlantDropDown" runat="server" OnInit="PlantDropDown_Init" DropDownStyle="DropDown" 
             AutoCompleteMode="SuggestAppend" 
            ItemInsertLocation="OrdinalText" AutoPostBack="false">


                </cc1:ComboBox>

Update: I tried using this sentence and I get this error:

$find("PlantDropDown") is null
[Break on this error] $find('PlantDropDown').add_propertyChanged(function(sender, e) {\r\n

jQuery javascript, , , .

: crescentfresh, .aspx :

    <input type="hidden" id="PlantDropDownID" value="<%= PlantDropDown.ClientID %>" />

javascript, javascript .aspx:

elem = document.getElementById('PlantDropDownID');
$find(elem.value).add_propertyChanged(function(sender, e) {
    if (e.get_propertyName() == 'selectedIndex') {
        var newValue = sender.get_textBoxControl().value;
    }
})
+3
2

, "propertyChanged" "selectedIndex":

$find('PlantDropDown').add_propertyChanged(function(sender, e) {
    if (e.get_propertyName() == 'selectedIndex') {
        var newValue = sender.get_textBoxControl().value;

        // persist selected value here...
    }
})

.NET .

, . , .get_value(), , .

Edit

> $find ( "PlantDropDown" ) null

, . . .NET . , :

$find('<%= PlantDropDown.ClientID %>')

> jQuery javascript

.

+8

, , , . , , , , - .

<script language="javascript" type="text/javascript">

    Sys.Application.add_load(initializePage);

    function initializePage() {
        $find('PlantDropDown').add_propertyChanged(function(sender, e) {    
        if (e.get_propertyName() == 'selectedIndex') {        
        var newValue = sender.get_textBoxControl().value;        
        // persist selected value here...    
        }})
    }

</script>
+1

Source: https://habr.com/ru/post/1718245/


All Articles