locked
Comboxbox ItemInserting ItemInserted event not firing RRS feed

  • Question

  • User141407843 posted

    Thank you for your help in advance.

    I have a very simple Combobox (autopostback = true, autocompletemode = suggest) that displays data from Oracle database. I specified oniteminserting and oniteminserted to validate an entered item that's not on the listed item. But these events are not getting fired at all. I searched everywhere and tried many suggestions to no avail. Many hours were spent on this already. Please help. BTW, I'm using NET 45 toolkit.

    Nick

    Tuesday, August 25, 2015 2:25 PM

Answers

  • User1724605321 posted

    Hi nlee,

    I put the debugging statement in those events, but never see it because it's never called. I did find that setting "AutoCompleteMode" to "none" made the event to fire.

    I test my code with setting "AutoCompleteMode" to "suggest" ,and it fires the "OnItemInserted" and "OnItemInserting" events. Have you updated the Ajax control toolkit to the latest version?

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 26, 2015 10:04 PM
  • User1724605321 posted

    Hi nlee,

    I test your code and it works fine ,the difference is i got the data from sql server , are you do something in ItemInserting or ItemInserted event ? tested code is for your reference:

            <cc1:ComboBox ID="ComboBox2" runat="server" DropDownStyle="Simple" AutoCompleteMode="Suggest"
                DataTextField="ContactName" MaxLength="80" OnItemInserted="ComboBox2_ItemInserted" OnItemInserting="ComboBox2_ItemInserting" DataValueField="CustomerId" DataSourceID="SqlDataSource1">
            </cc1:ComboBox>
            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                SelectCommand="SELECT CustomerId, ContactName FROM [Customers] WHERE City = @City" runat="server">
                <SelectParameters>
                    <asp:Parameter DefaultValue="London" Name="City" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>

    In addition , you could post a new thread for further discussion with other members ,since question in this thread has been solved .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 31, 2015 10:54 PM

All replies

  • User1724605321 posted

    Hi nlee2012 ,

    Comboxbox ItemInserting ItemInserted event not firing

    Could you please post your code about the combobox ,and you could set a breakpoint to the OnItemInserting event and confirm whether the event will be called .Basic usage of the two events is for your reference:

    <ajaxToolkit:ComboBox runat="server" ID="AjaxCombo" OnItemInserted="ItemInsertedEvent" OnItemInserting="ItemInsertingEvent" AutoPostBack="True" ItemInsertLocation="Append" />
    
    public void ItemInsertedEvent(object sender, AjaxControlToolkit.ComboBoxItemInsertEventArgs e)
    {
        
        // read from your data table in this event and bind the data to the combo boxs
    }
    
    public void ItemInsertingEvent(object sender, AjaxControlToolkit.ComboBoxItemInsertEventArgs e)
    {
        string itemToBeInserted = e.Item.Value;
        // make a call to add this item to your data table
    }

    You could also refer to links below for more details and demo:

    http://www.asp.net/web-forms/overview/ajax-control-toolkit/combobox/how-do-i-use-the-combobox-control-cs .

    https://ajaxcontroltoolkit.codeplex.com/wikipage?title=ComboBox%20Control .

    Best Regards,

    Nan Yu

    Wednesday, August 26, 2015 4:49 AM
  • User141407843 posted

    Hi,

    There really isn't much codes to post. I don't have much more than what you've included as example. It's a simple combobox with "OnItemInserted" and "OnItemInserting" events. I put the debugging statement in those events, but never see it because it's never called. I did find that setting "AutoCompleteMode" to "none" made the event to fire. Well, it defeats the purpose of using "ComboBox" option if the option "AutoCompleteMode" is turned off. The whole idea is to allow user to search by entering some text in addition to using "dropdown".

    Thanks.

    Wednesday, August 26, 2015 1:48 PM
  • User1724605321 posted

    Hi nlee,

    I put the debugging statement in those events, but never see it because it's never called. I did find that setting "AutoCompleteMode" to "none" made the event to fire.

    I test my code with setting "AutoCompleteMode" to "suggest" ,and it fires the "OnItemInserted" and "OnItemInserting" events. Have you updated the Ajax control toolkit to the latest version?

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 26, 2015 10:04 PM
  • User141407843 posted

    Hi,

    Thanks again for your reply.

    As per your suggestion, I upgraded the Ajax to the latest version, 15.1.3, and "firing" worked. However, I now have a bigger problem. The reason for using the combobox was to allow user to enter as many characters as they want into the box when searching for an item. It worked before both in IE and FF, now in IE, I can only enter only "1" character, hence defeating the purpose of using "combobox". Your help will be greatly appreciated.

    Here are codes:

    <asp:ComboBox ID="cbox" runat="server" 
    AutoPostBack="True" OnItemInserted="ItemInserting" OnItemInserting="ItemInserting"
    DataSourceID="ItemsList" DataTextField="ITEM_DESC"
    DataValueField="ITEM_NUMBER" MaxLength="80" DropDownStyle="Simple"  AutoCompleteMode="Suggest" >
    </asp:ComboBox>
    <asp:SqlDataSource ID="ItemsList" runat="server"
    ConnectionString="<%$ ConnectionStrings:OraSql %>"
    ProviderName="<%$ ConnectionStrings:OraSql.ProviderName %>"
    SelectCommand= "SELECT ITEM_NUMBER, ITEM_DESC FROM ITEM_LISTS WHERE ITEM_TYPE = :ITEM_TYPE ORDER BY ITEM_NUMBER">
    <SelectParameters>
    <asp:Parameter DefaultValue="FG" Name="ITEM_TYPE" Type="String" />
    </SelectParameters>
    </asp:SqlDataSource>

    Monday, August 31, 2015 6:02 PM
  • User1724605321 posted

    Hi nlee,

    I test your code and it works fine ,the difference is i got the data from sql server , are you do something in ItemInserting or ItemInserted event ? tested code is for your reference:

            <cc1:ComboBox ID="ComboBox2" runat="server" DropDownStyle="Simple" AutoCompleteMode="Suggest"
                DataTextField="ContactName" MaxLength="80" OnItemInserted="ComboBox2_ItemInserted" OnItemInserting="ComboBox2_ItemInserting" DataValueField="CustomerId" DataSourceID="SqlDataSource1">
            </cc1:ComboBox>
            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                SelectCommand="SELECT CustomerId, ContactName FROM [Customers] WHERE City = @City" runat="server">
                <SelectParameters>
                    <asp:Parameter DefaultValue="London" Name="City" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>

    In addition , you could post a new thread for further discussion with other members ,since question in this thread has been solved .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 31, 2015 10:54 PM