2011-08-15 31 views
2

我試圖做一個TextBox自動建議,我用Ajax控件來做到這一點。我正在給電影排列一些價值。我想通過使用用戶用來登錄網站的電子郵件ID過濾用戶表,從數據庫中提供該值。我無法將標籤值調用到下面的方法中。我在頁面加載過程中將用戶的電子郵件ID存儲在標籤中。幫助我做到這一點。AutoSuggest在一個asp.net使用Ajax控件

[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

如果您正在使用AJAX Control Toolkit的,你可以看到例如here

我不知道是什麼樣的標籤,但你需要設置UseContextKey=true;並指定ajaxToolkit:AutoCompleteExtender

上下文關鍵在你的情況,你可以將下面的代碼添加到Page.Load:

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

標籤存儲登錄到系統的用戶的電子郵件ID。我需要該值來檢索數據庫中的值 – rookie

+0

請參閱最新的答案。 –

0

這是因爲web方法是靜態的。在頁面加載時,將AutoCompleteExtender的上下文關鍵字設置爲標籤值(電子郵件ID)。另外,確保UseContextKey設置爲true。

相關問題