c# - AutoComplete TextBox is not populating other fields -


i having trouble getting textbox autocompleteextender populate other fields after selection has been made. if try same thing dropdownlist (changing control names appropriate point ddl instead of textbox) works perfectly.

from below sections of code can see may doing wrong? have spent days trying work!

aspx

<asp:textbox runat="server"      id="top_site_numtextbox"      size="6"      autopostback="true"      appenddatabounditems="true"     datatextfield="site_num"     datavaluefield="site_num"     datasourceid="sqldatasourcesite"     onselectedindexchanged="top_site_numtextbox_selectedindexchanged"      text='<%# bind("top_site_num") %>' /> <asp:autocompleteextender runat="server"     behaviorid="autocompleteex"     id="autocomplete1"      targetcontrolid="top_site_numtextbox"     servicepath="webservice.asmx"      servicemethod="getsitenum"     minimumprefixlength="2"      completioninterval="1000"     enablecaching="true"     completionsetcount="20"     delimitercharacters=";, :"     showonlycurrentwordincompletionlistitem="true" >     <animations>         <onshow>             <sequence>                 <%-- make completion list transparent , show --%>                 <opacityaction opacity="0" />                 <hideaction visible="true" />                 <%--cache original size of completion list first time animation played , set 0 --%>                 <scriptaction script="                     // cache size , setup initial size                     var behavior = $find('autocompleteex');                     if (!behavior._height) {                         var target = behavior.get_completionlist();                         behavior._height = target.offsetheight - 2;                         target.style.height = '0px';                     }" />                     <%-- expand 0px appropriate size while fading in --%>                 <parallel duration=".4">                     <fadein />                     <length propertykey="height" startvalue="0" endvaluescript="$find('autocompleteex')._height" />                 </parallel>             </sequence>         </onshow>         <onhide>             <%-- collapse down 0px , fade out --%>             <parallel duration=".4">                 <fadeout />                 <length propertykey="height" startvaluescript="$find('autocompleteex')._height" endvalue="0" />             </parallel>         </onhide>     </animations> </asp:autocompleteextender> 

c# codebehind

using system; using system.collections; using system.collections.generic; using system.configuration; using system.linq; using system.web; using system.web.security; using system.web.ui; using system.web.ui.htmlcontrols; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.data; using system.data.sqlclient; using system.web.services.protocols; using system.xml.linq; using system.web.services;  namespace project_review {     public partial class projectreviewadd : system.web.ui.page     {     string strconnstring = configurationmanager.connectionstrings["tesseract"].connectionstring;     string str;     sqlcommand com;      protected void page_load(object sender, eventargs e)     {         textbox top_site_numtextbox = formviewadd.findcontrol("top_site_numtextbox") textbox;          top_site_numtextbox.autopostback = true;         sqlconnection con = new sqlconnection(strconnstring);          if (!ispostback)         {             con.open();             str = "select site_num, site_name, site_address, site_county, site_post_code, cust_cust_ref scsite, sccust site_cust_num = cust_num order site_num";             com = new sqlcommand(str, con);             sqldatareader reader = com.executereader();             while (reader.read())             {                 top_site_numtextbox.tostring();             }             reader.close();             con.close();         }     }      private void clear()     {         textbox top_site_nametextbox = formviewadd.findcontrol("top_site_nametextbox") textbox;         textbox top_site_addresstextbox = formviewadd.findcontrol("top_site_addresstextbox") textbox;         textbox top_site_countytextbox = formviewadd.findcontrol("top_site_countytextbox") textbox;         textbox top_site_postcodetextbox = formviewadd.findcontrol("top_site_postcodetextbox") textbox;         textbox top_custtextbox = formviewadd.findcontrol("top_custtextbox") textbox;          top_site_nametextbox.text = "";         top_site_addresstextbox.text = "";         top_site_countytextbox.text = "";         top_site_postcodetextbox.text = "";         top_custtextbox.text = "";      }      protected void top_site_numtextbox_selectedindexchanged(object sender, eventargs e)     {         textbox top_site_numtextbox = formviewadd.findcontrol("top_site_numtextbox") textbox;         textbox top_site_nametextbox = formviewadd.findcontrol("top_site_nametextbox") textbox;         textbox top_site_addresstextbox = formviewadd.findcontrol("top_site_addresstextbox") textbox;         textbox top_site_countytextbox = formviewadd.findcontrol("top_site_countytextbox") textbox;         textbox top_site_postcodetextbox = formviewadd.findcontrol("top_site_postcodetextbox") textbox;         textbox top_custtextbox = formviewadd.findcontrol("top_custtextbox") textbox;          clear();         sqlconnection con = new sqlconnection(strconnstring);         con.open();         str = "select site_num, site_name, site_address, site_county, site_post_code, cust_cust_ref scsite, sccust site_cust_num = cust_num , site_num='" + top_site_numtextbox.text + "'";         com = new sqlcommand(str, con);         sqldatareader reader = com.executereader();         while (reader.read())         {             top_site_nametextbox.text = reader["site_name"].tostring();             top_site_addresstextbox.text = reader["site_address"].tostring();             top_site_countytextbox.text = reader["site_county"].tostring();             top_site_postcodetextbox.text = reader["site_post_code"].tostring();             top_custtextbox.text = reader["cust_cust_ref"].tostring();         }         reader.close();         con.close();     } } 

webservice.asmx (for autocompleteextender)

using system; using system.collections; using system.configuration; using system.data; using system.data.sqlclient; using system.collections.generic; using system.linq; using system.web; using system.web.services; using system.web.services.protocols; using system.xml.linq;  namespace projectreview.projectreview { /// <summary> /// summary description webservice /// </summary> [webservice(namespace = "http://tempuri.org/")] [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)] // allow web service called script, using asp.net ajax, uncomment following line. [system.web.script.services.scriptservice] public class webservice : system.web.services.webservice {     public webservice()     {         //uncomment following line if using designed components          //initializecomponent();      }     [webmethod]     public list<string> getsitenum(string prefixtext, int count)     {         sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["tesseract"].tostring());         con.open();         sqlcommand cmd = new sqlcommand("select site_num scsite site_num @site_num+'%' order site_num", con);         cmd.parameters.addwithvalue("@site_num", prefixtext);         sqldataadapter da = new sqldataadapter(cmd);         datatable dt = new datatable();         da.fill(dt);         list<string> site_num = new list<string>();         (int = 0; < dt.rows.count; i++)         {             site_num.add(dt.rows[i][0].tostring());         }         return site_num;     } } 

i have answer own question, ought share you. reason above code not doing wanted textboxes not have selectedindexchanged event. have textchanged events!

altering selectedindexchanged event textchanged enabled code work seamlessly.

thanks metalasp.net @ forums.asp.net


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -