I have a custom user control that serves as a reusable ASP
DropDownList
that asynchronously retrieves data from an RESTful
endpoint
我有一个自定义用户控件,用作可重用的ASP DropDownList,它从RESTful端点异步检索数据
<myControls:AjaxDropDown ID="ddlDropdown" runat="server" ServicePath="/MyWebService2.asmx/GetLetterTypes"/>
Inside the user control, I'm updating the drop down content via success in $.ajax
在用户控件内部,我通过$ .ajax成功更新下拉内容
$.ajax({
type: "GET",
dataType: "json",
url: $('#<%=textBoxUrlPath.ClientID %>').val(),
contentType: "application/json; charset=utf-8",
async: true,
success: function(res) {
onGetLetterTypesSuccess(res);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
How do I sync the data retrieved by $.ajax
with the code behind for the user control?
如何将$ .ajax检索的数据与用户控件的后台代码同步?
The reason I'm using $.ajax
rather than doing a partial update via the UpdatePanel
control is due UpdatePanel's inability to have multiple asynchronous calls at a time on a single page.
我之所以使用$ .ajax而不是通过UpdatePanel控件进行部分更新,是因为UpdatePanel无法在一个页面上同时进行多次异步调用。
2 个解决方案
#1
0
I decided to not go this route of client side updating, since it's directly opposing the Web Form structure. Instead I'll settle for a synchronous solution of make this call from the code behind and populating the DropDownList before serving the Page.
我决定不再采用这种客户端更新的方式,因为它直接反对Web Form结构。相反,我将寻求一个同步解决方案,从后面的代码进行调用,并在服务页面之前填充DropDownList。
#2
-1
I guess you can use asp.net hidden fields to store the selected values but yes it could become unnecessarily cumbersome through client side.
我猜你可以使用asp.net隐藏字段来存储选定的值但是它可能会通过客户端变得不必要地繁琐。
#1
0
I decided to not go this route of client side updating, since it's directly opposing the Web Form structure. Instead I'll settle for a synchronous solution of make this call from the code behind and populating the DropDownList before serving the Page.
我决定不再采用这种客户端更新的方式,因为它直接反对Web Form结构。相反,我将寻求一个同步解决方案,从后面的代码进行调用,并在服务页面之前填充DropDownList。
#2
-1
I guess you can use asp.net hidden fields to store the selected values but yes it could become unnecessarily cumbersome through client side.
我猜你可以使用asp.net隐藏字段来存储选定的值但是它可能会通过客户端变得不必要地繁琐。