AutoSuggest in a asp.net using Ajax controls

允我心安 提交于 2019-12-11 02:59:43

问题


I am trying to do auto suggest in a TextBox and I used Ajax controls to do so. I am giving movies array some values. I want to give that value from the database by filtering the user table with the email Id that the User used to Login to the website. I am not able to call the Label value into the method below. I have stored the email id of user in label during page load. help me to do that.

[System.Web.Services.WebMethodAttribute(),System.Web.UI.WebControls, System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
   // Create array of movies
    string[] movies = {"Joey", "Joester", "Joker", "Joeic", "Joic", "Shrek II"};

    // Return matching movies
    return (from m in movies where m.StartsWith(prefixText,StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}

回答1:


If you are using the AJAX Control Toolkit you can see example here.

I am not sure what is the label about, but you need to set UseContextKey=true; and specify the context key for the ajaxToolkit:AutoCompleteExtender

In your case you can add the following code to Page.Load:

if(!Page.IsPostBack)
{
  AutoCompleteExtenderID.ContextKey = LabeWtihEmal.Text;
}



回答2:


It's because the web method is static. On the load of your page, set the context key for your AutoCompleteExtender to the label value (email id). Also, make sure that UseContextKey is set to true.



来源:https://stackoverflow.com/questions/7067242/autosuggest-in-a-asp-net-using-ajax-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!