How to interact with database by using jQuery
-
I have an annoying problem. I use the autocomplete extender provided by ASP.NET in my Web Forms application written in C#. The autocomplete works good, no problem. I use the autocomplete with the serial_number textfield. If I want to fill in the product_name textfield based on what serial_number I have chosen I need to interact with the database. That is because the Web Method that provides data to the autocomplete must have a specific signature and its output parameters is an array of strings. Therefore once the serial_number is selected, I need to call a jQuery function that given the selected serial_number gets the corresponging product_name from the database (SQL Server). Any suggestion? Thanks UPDATE: The Web Method feeding the autocomplete [System.Web.Services.WebMethod] public static string[] GetProductId(string prefixText, int count) { string selectSQL = "SELECT srnum FROM demo_product WHERE srnum LIKE'" + prefixText + "' + '%'"; DataTable dtProdId = dbUtil.dbGetDataTable("EMPLOYEE", selectSQL); List<string> listProdId = new List<string>(); foreach (DataRow row in dtProdId.Rows) { listProdId.Add((string)row["SRNUM"]); } return listProdId.ToArray(); } And the markup in aspx file <asp:TextBox runat="server" ID="txtSRNum" BackColor="#FFFF66" AutoComplete="On"></asp:TextBox> <!-- Autocomplete extender for product serial number --> <ajax:AutoCompleteExtender ID="txtSRNum_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" ServicePath="" TargetControlID="txtSRNum" MinimumPrefixLength="1" ServiceMethod="GetProductId" CompletionSetCount="5" CompletionInterval="50" > </ajax:AutoCompleteExtender>
-
Answer:
What have you tried? Depending on your server-side configuration, your jQuery could look as simple as this: $.getJSON('/Products.aspx/LookupSerialNumber', {serial_number: $('#serial_number').val()}, function(json) { $('#product_name').val(json.product.product_name); } ); It's hard to give a more concrete example without knowing specifics.
CiccioMiami at Stack Overflow Visit the source
Related Q & A:
- How to Search using jQuery ASP.Net?Best solution by Stack Overflow
- How to create your own slider using jQuery?Best solution by Stack Overflow
- how to set value in ckeditor using jquery?Best solution by Stack Overflow
- how to submit form using jquery mobile?Best solution by Stack Overflow
- how to parse a xml file using jquery and phonegap?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.