Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoCompleteExtender issues
    primarykey
    data
    text
    <p>I'm using an AutoCompleteExtender in ASP.NET/C# to retrieve data from my database, along with the primary key of the field. When a name is chosen, the details (name/pk) are retrieved even before clicking submit, and it then passes these onto a hidden field.</p> <p>The issue I have is that if the user types in an incorrect name, the pk won't reset and will remain the same from the previous search - meaning that when the user clicks search, the old data will be displayed. </p> <p>Here is my AutoComplete service:</p> <pre><code> public string[] GetAutoComplete(string prefixText, int count) { string connection = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString; string sql = "SELECT * FROM SageAccount WHERE Name LIKE @prefixText AND Customer = 1 AND SageID IS NOT NULL"; SqlDataAdapter da = new SqlDataAdapter(sql, connection); da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%"; DataTable dt = new DataTable(); da.Fill(dt); List&lt;string&gt; Names = new List&lt;string&gt;(); foreach (DataRow dr in dt.Rows) { Names.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"].ToString() + " (" + dr["SageID"].ToString() + ")", dr["ID"].ToString())); } return Names.ToArray(); } </code></pre> <p>And the JavaScript used for populating the hiddenfield is:</p> <pre><code>function autoCompleteItemSelected(source, eventArgs) { var assocHiddenField = document.getElementById(source.get_id() + '_hidden'); assocHiddenField.value = eventArgs.get_value(); } </code></pre> <p>What is the best way to reset the hiddenfield if no results are returned? I do currently have a 'part working' solution, which is this bit of JavaScript:</p> <pre><code> function pageLoad() { $find('txtName')._onMethodComplete = function(result, context) { $find('txtName')._update(context, result, false); webservice_callback(result, context); }; } function webservice_callback(result, context) { var hiddenfield = document.getElementById('txtName_hidden'); if (result == "") hiddenfield.value = '0'; } </code></pre> <p>But if the user hits enter/clicks submit very quickly, it doesn't reset. If they don't click for a second or two it works, and resets the hiddenfield to 0.</p> <p>Any other ideas guys?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload