在 UpdatePanel 中使用 jQuery 进行用户控制
这不是问题的直接答案,但我确实通过阅读我在此处找到的答案将这个解决方案放在一起,我认为有人可能会觉得它很有用。
我试图在用户控件中使用 jQuery textarea 限制器。这很棘手,因为用户控件在 UpdatePanel 内部运行,并且它在回调时丢失了绑定。
如果这只是一个页面,这里的答案将直接适用。但是,用户控件不能直接访问 head 标记,也不能直接访问 UpdatePanel,正如某些答案所假设的那样。
我最终把这个脚本块放在了我的用户控件标记的顶部。对于初始绑定,它使用 $(document).ready,然后从那里使用 prm.add_endRequest:
<script type="text/javascript">
    function BindControlEvents() {
        //jQuery is wrapped in BindEvents function so it can be re-bound after each callback.
        //Your code would replace the following line:
            $('#<%= TextProtocolDrugInstructions.ClientID %>').limit('100', '#charsLeft_Instructions');            
    }
    //Initial bind
    $(document).ready(function () {
        BindControlEvents();
    });
    //Re-bind for callbacks
    var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    prm.add_endRequest(function() { 
        BindControlEvents();
    }); 
</script>
所以......只是想有人可能想知道这是有效的。