简体   繁体   中英

Creating an ASP.NET User Control With a Javascript API

I'm basically trying to figure out a good/clean way to organize controls that would have a public API like this:

<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" />

I've seen some 3rd party controls that our team uses such as Telerik and DevExpress that have similar functionality, but I have no idea how it is implemented. Can anyone provide some insight on a good/clean way to accomplish this?

It is recommended to create / initialize data unique in the WebUserControl's content (to avoid issues with the use multiple instances of this WebUserControl):

Register the startup script to create the javascript programmatic object (see the validating asp.net textBox using Javascript thread) to instantiate WebUserControl reference (like DevExpress recommends in the www.devexpress.com/kb=K18373 KB).

我遇到了同样的问题,所幸我发现了有趣的博客文章- 使用ASP.NET Ajax和Web服务动态创建ASP.NET用户控件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM