【问题标题】:Creating an ASP.NET User Control With a Javascript API使用 Javascript API 创建 ASP.NET 用户控件
【发布时间】:2011-10-01 10:57:25
【问题描述】:

我基本上是想找出一种好的/干净的方式来组织具有这样公共 API 的控件:

<script>
    function buttonClicked() {
        var myUserControl = SomehowGetReferenceToThisUserControl("UserControl");

        myUserControl.AjaxReload();
    }
</script>

<a href="javascript:buttonClicked()">Refresh the User Control!</a>
<myControls:MyUserControl ID="UserControl" runat="server" />

我已经看到我们团队使用的一些 3rd 方控件,例如 Telerik 和 DevExpress,它们具有类似的功能,但我不知道它是如何实现的。任何人都可以提供一些关于实现此目的的好/干净的方法的见解吗?

【问题讨论】:

  • 扩展器不按照你的要求做,他们有干净的 api,他们与网络服务交互,他们可以重新渲染也导致回发。
  • @Deeptechtons:你告诉我。如果他们这样做,我不知道他们或他们有什么功能可以用于此。愿意提供答案吗?
  • 我确实有答案,只是如果你知道扩展器并且它对你不起作用,我会浪费其他人的时间,我会用代码示例更新你。

标签: javascript asp.net api user-controls


【解决方案1】:

建议在 WebUserControl 的内容中创建/初始化唯一的数据(以避免使用此 WebUserControl 的多个实例时出现问题):

注册启动脚本以创建 javascript 编程对象(参见 validating asp.net textBox using Javascript 线程)以实例化 WebUserControl 引用(如 www.devexpress.com/kb=K18373 KB 中的 DevExpress 建议)。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,幸运的是我发现了有趣的博文 - Dynamically create ASP.NET user control using ASP.NET Ajax and Web Service.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2018-11-18
      相关资源
      最近更新 更多