嘿我想在asp.net中使用自動完成jQuery在一個default1.aspx頁面上使用的控件。我的控件是在註冊文件夾中的searchinput.ascx。我的問題是我在searchinput控件的代碼文件上編寫了web方法(getmylist)。但該方法從未被調用過。誰能幫助我在asp.net控件上自動完成
0
A
回答
0
你可以找到笏你需要有一個開始。 此外,顯示您的ajax調用,以便我可以嘗試幫助它,它不工作。 你的方法寫作一個Web方法,並從jquery自動完成ajax調用應該工作得很好,否則。
0
它很難幫你沒有代碼,但一些常見的原因可能是:
你沒有正確使用的ClientID值 - asp.net控件不具有實際加價爲同一ID他們在設計器中執行
您的web方法有錯誤 - 您應該按f12打開您的web開發人員工具欄並轉至NET選項卡(至少在Firefox中)以查看500錯誤代碼或類似內容正在退回
0
創建Web方法如下所示:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] GetPatientFirstName(string prefix)
{
List<string> customers = new List<string>();
using (SqlConnection conn = new SqlConnection())
{
string connectionstring = CCMMUtility.GetCacheForWholeApplication();
conn.ConnectionString = connectionstring;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select distinct top(10) PatientFirstname from tblMessage where " +
"PatientFirstname like '%'+ @SearchText + '%' order by PatientFirstname";
cmd.Parameters.AddWithValue("@SearchText", prefix);
cmd.Connection = conn;
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(string.Format("{0}", sdr["PatientFirstname"]));
}
}
conn.Close();
}
return customers.ToArray();
}
}
這裏是html代碼:
$(document).ready(function() {
$('[ID$=txtPatientFirstname]').live('keyup.autocomplete', function() {
$(this).autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/Resources/WebService.asmx/GetPatientFirstName") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
},
minLength: 1
});
});
});
這是工作的例子......希望這能解決您的問題..
相關問題
- 1. 在ASP.Net中使用jQuery自動完成插件 - 提交自動完成
- 2. asp.NET jqueryUI自動完成
- 3. JQUERY自動完成和asp.NET
- 4. JQuery自動完成+ Asp.net MVC
- 5. Telerik ASP.NET,自動完成RadTextbox
- 6. jQuery自動完成和ASP.NET
- 7. ASP.NET MVC 3自動完成
- 8. ASP.NET自動完成DropDownList
- 9. PostgreSQL的自動完成 - ASP.NET
- 10. ASP.NET Jquery自動完成
- 11. ASP.NET中的模糊自動完成文本框控件
- 12. 在jQuery自動完成控件上按下轉義
- 13. asp.net自動完成和IE自動完成
- 14. 自動完成文本框控件
- 15. Silverlight自動完成文本框控件?
- 16. XForms中的自動完成控件
- 17. 在ASP.Net JQUery自動完成Web服務
- 18. 在asp.net c中自動完成屬性#
- 19. 附上事件的jquery自動完成
- 20. 在Ext.net(ASP.NET)中上傳完成事件?
- 21. 如何使用asp.net自動完成擴展器獲取焦點上的完整自動完成列表?
- 22. jQuery-UI自動完成插件和黑莓自動完成器
- 23. jQuery自動完成插件jQuery UI自動完成
- 24. asp.net生成控件動態
- 25. ASP.NET中的Google Places自動完成
- 26. JSON自動完成ASP.NET Jquery UI
- 27. ASP.Net MVC - 停止自動完成密碼
- 28. JQuery UI自動完成不工作asp.net
- 29. JQuery自動完成與ASp.Net web服務
- 30. 試圖讓JQuery的自動完成Asp.Net
嘿,顯示一些代碼。 – Aristos
你有這些數據註釋嗎? '[WebMethod]'和[ScriptMethod]' –
是你的問題解決與我們的答案,然後不要忘記接受正確的答案.. –