I am using ASP.NET 3.5...I have a text box where I am using the AutoCompleteExtender for search.

When user enter the key the serach shows the "ProjectNumber-ProjectName" in the search result....after selecting any of this...only ProjectNumber is entered in the textbox (I am using hidden control to store key values)...everything works fine till here.

Now I have a problem with values stored in the hidden control...for example in the text box there are three ProjectNumbers ..A,B,C....now I go ahead and delete all these three and enter the key word again...the search work fine but when I select any value the Text box is populated with old value (coming from hidden control) like A,B,C and then new value D

Please suggest me how I can assign the hidden text box value with the new text box values after the selection is done...

function KeySelected(source, eventArgs) {

            var labelVal = document.getElementById('<%=this.Hidden1.ClientID%>').value;
          var userValues = "";
          if (labelVal == "") {
              userValues = eventArgs.get_value();
          else {
              userValues = labelVal + "," + eventArgs.get_value();

          document.getElementById('<%=this.Hidden1.ClientID%>').value = userValues;

        //Assigning the hidden value to text box
          document.getElementById('<%=this.TxtProject.ClientID%>').value = userValues;



asp:textbox id="TxtProject" runat="server" Width="246px" MaxLength="100" ></asp:textbox>*<FONT face="Arial" size="2">Any&nbsp;text&nbsp;Separated&nbsp;by&nbsp;comma&nbsp;will&nbsp;give&nbsp;separate&nbsp;results</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD> 

<asp:AutoCompleteExtender ID="TxtProject_AutoCompleteExtender" runat="server" DelimiterCharacters="," MinimumPrefixLength="1" Enabled="True" ServicePath="AutoCompleteWebServices.asmx" OnClientItemSelected="KeySelected" CompletionListItemCssClass="ac_listItem" CompletionListHighlightedItemCssClass="ac_hl_listitem" 

ServiceMethod="GetProjectList" TargetControlID="TxtProject" > 


Recommended Answers

All 2 Replies

Hi Gaurav,
I'm quite new to this too - and I'm trying to do a similar thing.
I'm not sure if this is a good idea or not - but you could compare the number of commas in the text field and the hidden field?
If they match, then add the new value on the end;
else if one is zero, then set equal to the new value.

Something like that?


Just try to make the hidden text box empty before u fill it up again.

document.getElementById('<%=this.TxtProject.ClientID%>').value = ' '
//Assigning the hidden value to text box
document.getElementById('<%=this.TxtProject.ClientID%>').value = userValues;

Mark as solved it it helps you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.