locked
AutoCompleteExtender as a Control giving problem RRS feed

  • Question

  • Hi,

    I have created an autocomplete control where i have combined Text box with auto complete extender. Now it works perfactly if i am not giving it TextChanged Event. but if i give it change event then i doent allow me to add anything in the form for few mins. if i select anything from a drop down(ie. if postback occurs) it allows me to add in controls again.

     

    my code

     

    public class ISPLAutoComplete : CompositeControl
      {
        private AutoCompleteExtender _autoComplete;
        private TextBox _textboxTarget;
        private HiddenField _hdn;
        //private Image img;
        #region Custom Properties
    
        public bool CheckForValueExists
        {
          get;
          set;
        }
    
        public string WebServiceMethod
        {
          get
          {        
            if (ViewState["WSM" + ID] == null)
            {
              ViewState["WSM" + ID] = "";
            }
    
            return ViewState["WSM" + ID].ToString();
          }
          set
          {
            ViewState["WSM" + ID] = value;
          }
        }
    
    
        public string WebServicePath
        {
          get
          {
            if (ViewState["WSP" + ID] == null)
            {
              ViewState["WSP" + ID] = "";
            }
    
            return ViewState["WSP" + ID].ToString();
          }
          set
          {
            ViewState["WSP" + ID] = value;
          }
        }
    
        public int MinPrefixLength
        {
          get;
          set;
        }
        public string DisplayField
        {
          get
          {
            if (ViewState["DF" + ID] == null)
            {
              ViewState["DF" + ID] = "";
            }
    
            return ViewState["DF" + ID].ToString();
          }
          set
          {
            ViewState["DF" + ID] = value;
          }
        }
        public string ValueField
        {
          get
          {
            if (ViewState["VF" + ID] == null)
            {
              ViewState["VF" + ID] = "";
            }
    
            return ViewState["VF" + ID].ToString();
          }
          set
          {
            ViewState["VF" + ID] = value;
          }
        }
    
        public string AdditionalArgument
        {
          get
          {
            if (ViewState["AddlArgs" + ID] == null)
              ViewState["AddlArgs" + ID] = "";
    
            return ViewState["AddlArgs" + ID].ToString();
          }
          set
          {
            ViewState["AddlArgs" + ID] = value;
          }
        }
    
        public string BehaviourId
        {
          get;
          set;
        }
    
        public string SelectedText
        {
          get
          {
            EnsureChildControls();
            return _textboxTarget.Text;
          }
          set
          {
            EnsureChildControls();
            _textboxTarget.Text = value;
          }
        }
    
        public string SelectedValue
        {
          get
          {
            EnsureChildControls();
            return _hdn.Value;
          }
          set
          {
            EnsureChildControls();
            _hdn.Value = value;
          }
        }
    
        public string ValidationString
        {
          get
          {
            return string.IsNullOrEmpty(SelectedValue) ? "" : SelectedValue;
          }
        }
        #endregion
    
        #region Constant members
        private const string AutocompleteJs = "ISPLControls.Resources.ISPLAutoCompleteJS.js";
        #endregion
    
        #region AutoComplete Events
        public delegate void AutoCompleteSelectionChangedEventHandler(object sender, EventArgs e);
        public event AutoCompleteSelectionChangedEventHandler AutoCompleteSelectionChanged;
        protected virtual void OnAutoCompleteSelectionChanged(object sender, EventArgs e)
        {
          if (AutoCompleteSelectionChanged != null) AutoCompleteSelectionChanged(sender, e);
        }
    
        
    
        #endregion
    
        
    
        protected override void OnInit(EventArgs e)
        {
          //Page.RegisterRequiresControlState(this);
    
          //InitializeControls();
    
          // Include the GridViewJs.js, which includes all Js related functions
          var t = GetType();
          string url = Page.ClientScript.GetWebResourceUrl(t, AutocompleteJs);
    
          if (!Page.ClientScript.IsClientScriptIncludeRegistered(t, AutocompleteJs))
            Page.ClientScript.RegisterClientScriptInclude(t, AutocompleteJs, url);
    
    
          base.OnInit(e);      
        }
    
        //private void InitializeControls()
        //{
          
        //}
    
        protected void TextboxTargetTextChanged(object sender, EventArgs e)
        {
          if(AutoCompleteSelectionChanged == null) return;
          AutoCompleteSelectionChanged(sender, e);
        }
    
        protected override void CreateChildControls()
        {
          //base.CreateChildControls();
          this.Controls.Clear();
    
          _hdn = new HiddenField {ID = "hdn" + ID};
          Controls.Add(_hdn);
    
          _autoComplete = new AutoCompleteExtender
                    {
                      ID = "autoCompleteMain" + ID,
                      CompletionInterval = 100,
                      CompletionSetCount = 10,
                      EnableCaching = true,
                      BehaviorID = BehaviourId
                    };
    
    
          Controls.Add(_autoComplete);
    
          _textboxTarget = new TextBox {ID = "textBoxTarget" + ID};
          //textboxTarget.Style.Add(HtmlTextWriterStyle.BackgroundImage, "url(../Images/Default/loading-thumb.gif)");      
    
          _textboxTarget.Attributes.Add("alt", _hdn.ClientID);
          _textboxTarget.SkinID = "txtWithoutBlur";
    
          _textboxTarget.TabIndex = TabIndex;
    
          _textboxTarget.Style.Add(HtmlTextWriterStyle.Width, Width.Value <= 0 ? "250px" : Width.Value.ToString());
    
    
          if (AutoCompleteSelectionChanged != null)
          {
            _textboxTarget.TextChanged += TextboxTargetTextChanged;
          }
          Controls.Add(_textboxTarget);
    
          _autoComplete.TargetControlID = _textboxTarget.ID;
          _autoComplete.CompletionSetCount = 10;
          _autoComplete.CompletionInterval = 100;
          _autoComplete.MinimumPrefixLength = (MinPrefixLength == 0 ? 2 : MinPrefixLength);
          _autoComplete.OnClientItemSelected = "ItemSelected";
    
          _autoComplete.CompletionListCssClass = "autocomplete_completionListElement";
          _autoComplete.CompletionListItemCssClass = "autocomplete_listItem";
          _autoComplete.CompletionListHighlightedItemCssClass = "autocomplete_highlightedListItem";
    
          _autoComplete.ServiceMethod = WebServiceMethod;
          _autoComplete.ServicePath = WebServicePath;
          _autoComplete.UseContextKey = true;
          _autoComplete.ContextKey = DisplayField + ":" + ValueField + ":" + AdditionalArgument;
    
    
          _textboxTarget.Attributes.Add("onkeypress", "javascript:ShowIcon('" + _textboxTarget.ClientID + "');");
          _textboxTarget.Attributes.Add("onblur", "javascript:HideIcon('" + _textboxTarget.ClientID + "');");
    
        }
    
        public void Clear()
        {
          SelectedValue = "";
          SelectedText = "";
        }
    
        protected override void OnPreRender(EventArgs e)
        {
          base.OnPreRender(e);
    
          if (Page != null)
          {
            //Page.RegisterRequiresPostBack(this);
          }
    
          _autoComplete.TargetControlID = _textboxTarget.ID;
          _autoComplete.CompletionSetCount = 10;
          _autoComplete.CompletionInterval = 100;
          _autoComplete.MinimumPrefixLength = (MinPrefixLength == 0 ? 2 : MinPrefixLength);
          _autoComplete.OnClientItemSelected = "ItemSelected";
    
          _autoComplete.CompletionListCssClass = "autocomplete_completionListElement";
          _autoComplete.CompletionListItemCssClass = "autocomplete_listItem";
          _autoComplete.CompletionListHighlightedItemCssClass = "autocomplete_highlightedListItem";
    
          _autoComplete.ServiceMethod = WebServiceMethod;
          _autoComplete.ServicePath = WebServicePath;
          _autoComplete.UseContextKey = true;
          _autoComplete.ContextKey = DisplayField + ":" + ValueField + ":" + AdditionalArgument;
        }
    
    
    
    
    
        
      }
    
    Saturday, February 19, 2011 1:22 PM

All replies

  • anyone???
    Friday, February 25, 2011 4:44 AM
  • The issue seems to be with TabIndex.

     

    I tried this code

    <asp:TextBox ID="txtEntity" runat="server" SkinID="txtWithoutBlur" Width="300px" TabIndex="4"/>
    <AjaxToolkit:AutoCompleteExtender ID="aceEntity" runat="server"
    ServicePath="../../Common/CommonWebService.asmx"
    ServiceMethod="GetEntityName" ContextKey="EntityName:EntityID:V"
    CompletionInterval="100" CompletionSetCount="10" MinimumPrefixLength="1" 
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
    CompletionListCssClass="autocomplete_completionListElement"
    CompletionListItemCssClass="autocomplete_listItem"
    OnClientItemSelected="ClientItemSelected"
    TargetControlID="txtEntity"
    />


    Here i have given TabIndex="4" to txtEntity. It does not works here. But if i remove the tabindex property it works. The same thing happens with the Autocomplete i have developed.

     

    Is there any issue with UpdatePanel/Tabindex/Autocomplete extender?

    Friday, March 4, 2011 9:02 AM