title: Jquery autocomplete search not working in usercontrol(ascx) page in asp.net
body: <p>I have text box in UserControle(ascx) page of Asp.net website, I use automcomplete search on this text box, this is working fine when i put this textbox on aspx page. But in ascx(usercontrol) page it is not working.</p>
  
  <p>My textbox is:</p>
  
  <pre><code>  &lt;asp:TextBox ID="txtCityUsed" Style="width: 91.2%; height: 13px; float: left;"
                                                              Width="" runat="server"&gt; 
  </code></pre>
  
  <p>I am calling below two method from page load of user controle page,</p>
  
  <pre><code>protected void SetAutocompleteTextbox()
  {
      StringBuilder sbLVAutocomplete;
      try
      {
          sbLVAutocomplete = new StringBuilder();
          sbLVAutocomplete.AppendLine("&lt;script type=\"text/javascript\"&gt;");
          sbLVAutocomplete.AppendLine("           function autoFetchRecord_txtCityUsed() {");
          sbLVAutocomplete.AppendLine("               if (document.getElementById(\"" + txtCityUsed.ClientID + "\").value.length &gt;=1) {");
          sbLVAutocomplete.AppendLine("                   $(\"#" + txtCityUsed.ClientID + "\").autocomplete({");
          sbLVAutocomplete.AppendLine("                       source: function(request, response) {");
          sbLVAutocomplete.AppendLine("                           $.ajax({");
          sbLVAutocomplete.AppendLine("                               type: \"POST\",");
          sbLVAutocomplete.AppendLine("                               contentType: \"application/json; charset=utf-8\",");
          sbLVAutocomplete.AppendLine("                               url: \"LandingForPortal.aspx/GetListOfCity\",");
          sbLVAutocomplete.AppendLine("                               data: \"{'Name':'\" + document.getElementById('" + txtCityUsed.ClientID + "').value + \"','strRiskStartDate':'\" + document.getElementById('" + txtPolicyStartDate.ClientID + "').value + \"'}\",");
          sbLVAutocomplete.AppendLine("                               dataType: \"json\",");
          sbLVAutocomplete.AppendLine("                               success: function (data) {");
          sbLVAutocomplete.AppendLine("                                   if (data.d.length == 0){ ");
          sbLVAutocomplete.AppendLine("                                       alert('No Data Found!');");
          sbLVAutocomplete.AppendLine("                                       document.getElementById('" + txtCityUsed.ClientID + "').value =\"\";");
          sbLVAutocomplete.AppendLine("                                       document.getElementById('" + hdnVehicleUsedCityCode.ClientID + "').value =\"\";");
          sbLVAutocomplete.AppendLine("                                       document.getElementById('" + hdnVehicleUsedOfficeCode.ClientID + "').value =\"\";");
          sbLVAutocomplete.AppendLine("                                       document.getElementById('" + hdnVehicleUsedOfficeName.ClientID + "').value =\"\";");
          sbLVAutocomplete.AppendLine("                                       document.getElementById('" + hdnVehicleUsedParentOfficeCode.ClientID + "').value =\"\";");
          sbLVAutocomplete.AppendLine("                                   }");
          sbLVAutocomplete.AppendLine("                                   response($.map(data.d, function (item) {");
          sbLVAutocomplete.AppendLine("                                       return {");
          sbLVAutocomplete.AppendLine("                                           value: item.City,");
          sbLVAutocomplete.AppendLine("                                           CityCode: item.CityCode,");
          sbLVAutocomplete.AppendLine("                                           OfficeCode: item.OfficeCode,");
          sbLVAutocomplete.AppendLine("                                           OfficeLocation: item.OfficeLocation,");
          sbLVAutocomplete.AppendLine("                                           ParentOfficeCode: item.ParentOfficeCode");
          sbLVAutocomplete.AppendLine("                                       }");
          sbLVAutocomplete.AppendLine("                                   }))");
          sbLVAutocomplete.AppendLine("                                   },");
          sbLVAutocomplete.AppendLine("                                   error: function (result) {");
          sbLVAutocomplete.AppendLine("                                       alert(data);");
          sbLVAutocomplete.AppendLine("                                   }");
          sbLVAutocomplete.AppendLine("                           });");
          sbLVAutocomplete.AppendLine("                       },");
          sbLVAutocomplete.AppendLine("                       ");
          sbLVAutocomplete.AppendLine("                       open: function(){");
          sbLVAutocomplete.AppendLine("                           $('.ui-autocomplete').css('width', '300');");
          sbLVAutocomplete.AppendLine("                       },");
          sbLVAutocomplete.AppendLine("                       select: function (event, ui) {");
          sbLVAutocomplete.AppendLine("                           if (ui.item) {");
          sbLVAutocomplete.AppendLine("                               $('#" + txtCityUsed.ClientID + "').val(ui.item.value);");
          sbLVAutocomplete.AppendLine("                               $('#" + hdnVehicleUsedCityCode.ClientID + "').val(ui.item.CityCode);");
          sbLVAutocomplete.AppendLine("                               $('#" + hdnVehicleUsedOfficeCode.ClientID + "').val(ui.item.OfficeCode);");
          sbLVAutocomplete.AppendLine("                               $('#" + hdnVehicleUsedOfficeName.ClientID + "').val(ui.item.OfficeLocation);");
          sbLVAutocomplete.AppendLine("                               $('#" + hdnVehicleUsedParentOfficeCode.ClientID + "').val(ui.item.ParentOfficeCode);");
          sbLVAutocomplete.AppendLine("                               return false;");
          sbLVAutocomplete.AppendLine("                           }");
          sbLVAutocomplete.AppendLine("                       },");
          sbLVAutocomplete.AppendLine("                       minLength: 3");
          sbLVAutocomplete.AppendLine("                   });");
          sbLVAutocomplete.AppendLine("               }");
          sbLVAutocomplete.AppendLine("           }");
          sbLVAutocomplete.AppendLine("&lt;/script&gt;");
  
          if (!Page.ClientScript.IsStartupScriptRegistered("Autocomplete"))
          {
              //Registering startup script Autocomplete
              Page.ClientScript.RegisterStartupScript(typeof(string), "Autocomplete", sbLVAutocomplete.ToString());
          }
      }
      catch (Exception ex)
      {
          //ErrorMessage("ERROR", "ERROR from SetAutocompleteTextbox()" + ex.Message);
  
      }
      finally
      {
      }
  }
  protected void AddAttributesAutoComplete()
  {
      try
      {
          txtCityUsed.Attributes.Add("onkeyup", "autoFetchRecord_txtCityUsed();");
  
      }
      catch (Exception ex)
      {
          //  ErrorMessage("ERROR", "ERROR from AddAttributesAutoComplete()" + ex.Message);
      }
      finally
      {
      }
  }
  </code></pre>
  
  <p><strong>This is the method which get call when i enter search text in textbox</strong></p>
  
  <pre><code>[System.Web.Services.WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public static object GetListOfCity(string Name, string strRiskStartDate)
  {
      ServiceResult arrLVServiceResult;
      GCIntegrationClient objCVGCIntegrationClient = new GCIntegrationClient();
      arrLVServiceResult = objCVGCIntegrationClient.CityWherePrimarilyUsedLOV_GetObjectData(Convert.ToString(strProductCode), Convert.ToString(strTokenId), Convert.ToString(strRiskStartDate), Convert.ToString(""), Convert.ToString(Name));
      return arrLVServiceResult.UserData.CityGrid;
  }
  </code></pre>
  
  <p>But when i enter search text for autocomplete search in usercontrol(ascx) page then above method didn't get call but page_load occured. while pageload should not occure and only this above method should get call....
  please any body help me...I can not change the page and can't use popup for autosearch</p>