This is a migrated thread and some comments may be shown as answers.

Web Forms Autocomplete, click on dropdown event

2 Answers 127 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Veteran
Andrey asked on 26 Oct 2020, 12:25 PM

Hi,

I have the telerik:RadAutoCompleteBox  in aspx page server side. It works five. Postback works fine on the tab key or loosing focus of the text field. But now I need to have what was selected if user selected a value with click in the dropdown selection box. Here are the steps:

1. User began typing and mouse-clicked on some line in the dropdownbox. The text was populated. No post-back event fired. The text is, let's say, "My selection 1"

2. User changed the text (to My selection 2) and clicked on an another field. Post-back event fired. And I have the text value "My selection 2" in the post-back method on the server.

What I need is a post-back event to save the "My selection 1" value after the step 1. Is it possible to do?

Here is my code:

<telerik:RadAutoCompleteBox ID="txtAgtName" AllowCustomEntry="true" RenderMode="Lightweight" runat="server" TabIndex="15" EmptyMessage="Please type Agent's name here"
                                            DataSourceID="SqlDataAgentName" DataTextField="AgentName" InputType="Text" Width="170px" DropDownWidth="150px" OnTextChanged="txtAgent2Email_TextChanged">
                                            <TextSettings SelectionMode="Single" />
                                        </telerik:RadAutoCompleteBox>

2 Answers, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 28 Oct 2020, 01:10 PM

Hello Andrey,

The TextChanged event is triggered only on blur of the input but as the input never blurs, the event is not triggered, hence no postback.

If you need to access the item that was clicked, you can use the following OnClientLoad event handler of the AutoCompleteBox:

function OnClientLoad(sender, args) {
    sender._dropDown.on({
        "dropDownItemClicked": function (args) {
            console.log(args.get_item())
            sender.get_inputElement().blur();
        }
    });
}

This will actually blur the input once an item from the dropdown is clicked, which will trigger the postback.

Regards,
Peter Milchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Andrey
Top achievements
Rank 1
Veteran
answered on 03 Nov 2020, 11:32 AM
Thanks!
Tags
AutoCompleteBox
Asked by
Andrey
Top achievements
Rank 1
Veteran
Answers by
Peter Milchev
Telerik team
Andrey
Top achievements
Rank 1
Veteran
Share this question
or