Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,


I have using an JQuery Autocompleter to show the list of values from database inside an textbox.

Its works fine, untill i used TEXTCHANGED event of that textbox. Now i need to use TEXTCHANGED event to update user changed values.

While i type "a" it will shows me list of words starts with "a" like "asp.net, asp..."

Problem is, if user select the values from "mouse" it will lost focus and TEXTCHANGED event raised. But while i hit TAB or ENTER key its works fine.

Hence i thought of using "HIDDEN FIELD" and save the value of textbox and retrieve it.
After big research i found the value, which was assigned to TEXTBOX inside "autocomplete.js"
I did check it out by made an "alert()"

I'm newer to JQuery, Please help me out.

My code is below...

XML
<link href="../../StyleSheets/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="../../StyleSheets/SearchScript/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../../StyleSheets/SearchScript/jquery.autocomplete.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=txt_custname.ClientID%>").autocomplete('CustomerHandler.ashx');
        var data = $('#txt_custname.ClientID').value;
        $('#hidden').val(data);
        if(data != "")
        {
        var hid = $('#hidden').value;
        alert(hid);
        }
     });
</script>

<asp:HiddenField ID="hidden" runat="server"/>
Posted
Updated 11-Aug-11 2:53am
v4

1 solution

You don't want to post back on text changed. As you say, switching focus to the auto complete box will fire that event, and that's probably not what you want. (Are you talking about an ASP.net 'event' or a client-side Javascript event? You used lower case which implies client side.)

If you need live updating when the text is changed, use AJAX to refresh other page values in the background. If you don't, let the user choose lots of values and then resubmit the form.
 
Share this answer
 
Comments
J.Karthick 11-Aug-11 8:49am    
Thanks for your reply...

And sorry for the confusion that was Server side event of TEXTCHANGED
BobJanova 11-Aug-11 10:09am    
Okay. So yeah, don't do that. Hooking a server side changed event causes a postback to happen when the user leaves that field, so they see the page reloaded, lose their place, see a loading cursor etc just from tabbing out of a field. If you want the other fields to update immediately, use AJAX and a client side event. (I think you can do this with an update panel in ASP.net, or just use jQuery to submit a vanilla AJAX request and write an ashx handler for it to return the updated data.)
J.Karthick 11-Aug-11 10:43am    
yaaa...May be your rite... but i think it was an tedious Process....

But i found an simple solution. I just remove the Autopostback Property from my Textbox. Hence its just postback automatically from that nearby Control's Postback. And i have already wrote event for TEXTCHANGED to update all controls. Hence its works fine....

Thanks for your support... Cheers...:)

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