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

RadNumericTextBox postback as-you-type

1 Answer 173 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ravin
Top achievements
Rank 1
Ravin asked on 23 Jul 2013, 05:19 AM
I'm implementing a search-as-you-type feature using RadNumericTextBox. What should happen is when the user pauses typing on the RadNumericTextBox for half a second, it should perform a postback and my search results should get refreshed. I can catch the OnKeyPress client event of RadNumericTextBox, but the problem is that textbox's internal numeric value does not get updated until the textbox goes out-of-focus. How can I make it do a postback with the updated value while the user is typing on the textbox?.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 25 Jul 2013, 02:02 PM
Hello Ravin,

Thank you for contacting us.

In your case you could use the blur() function of the client-side RadTextBox object to force a postback.

Here is an simple example on how you can force postback with time interval between KeyPress client-side event:
<telerik:RadCodeBlock runat="server">
    <script language="javascript" type="text/javascript">
        var timer = null;
 
        function keyPressed(sender, args) {
            clearTimeout(timer);
            timer = setTimeout(function () {
                var textBox = $find("<%=RadTextBox1.ClientID %>");
                textBox.blur();
            }, 1500)
        }
    </script>
</telerik:RadCodeBlock>
<telerik:RadTextBox ID="RadTextBox1" runat="server" AutoPostBack="true" OnTextChanged="RadTextBox1_TextChanged">
    <ClientEvents OnKeyPress="keyPressed" />
</telerik:RadTextBox>

Then on the server-side TextChanged event you may set the focus back to true:
protected void RadTextBox1_TextChanged(object sender, EventArgs e)
{
    RadTextBox1.Focus();
     //your search logic
}

Hope this helps.

 

Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Input
Asked by
Ravin
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or