首页 > 解决方案 > 使用 javascript 更新用户控件时,如何同步后面的代码?

问题描述

我有一个自定义用户控件,可用作从端点ASP DropDownList异步检索数据的可重用控件RESTful

<myControls:AjaxDropDown ID="ddlDropdown" runat="server" ServicePath="/MyWebService2.asmx/GetLetterTypes"/>

在用户控件中,我通过成功更新下拉内容$.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);
  }
});

如何将检索到的数据$.ajax与用户控件背后的代码同步?

我使用$.ajax而不是通过UpdatePanel控件进行部分更新的原因是由于 UpdatePanel 无法在单个页面上一次进行多个异步调用。

标签: c#asp.net.netajax.net-4.0

解决方案


我决定不走这条客户端更新路线,因为它直接反对 Web 表单结构。相反,我将满足于从后面的代码进行此调用并在提供页面之前填充 DropDownList 的同步解决方案。


推荐阅读