简体   繁体   English

部分渲染后Javascript没有执行

[英]Javascript not executing after partial rendering

I have a asp.net panel that is initially hidden and is shown when a button is clicked. 我有一个最初隐藏的asp.net面板,并在单击按钮时显示。 There is javascript inside that panel and it doesn't execute after the panel is set to be visible. 该面板中有javascript,并且在面板设置为可见后不会执行。 I can see that javascript function gets outputted on page but it is not called. 我可以看到javascript函数在页面上输出但是没有被调用。 What can I do to make it so that function gets called? 我该怎么做才能调用函数? Here is an example: 这是一个例子:

<asp:LinkButton id="lbtn" runat="server" Text="show" OnClick="lbtn_Click" />
    <asp:UpdatePanel id="upnl" runat="server" UpdateMode="Conditional">
       <contenttemplate>
        <asp:panel id="pnlContent" runat="server" visible="false">
            content initially hidden.

            <script>
                alert('done!');
            </script>
        </asp:panel>
    </contenttemplate>
    <triggers>
        <asp:AsyncPostBackTrigger ControlID="lbtn"/>
    </triggers>
</asp:UpdatePanel>

You'll probably want to have some sort of end request method that gets called whenever an ajax method is called. 您可能希望在调用ajax方法时调用某种结束请求方法。 this would have to be under the script resource. 这必须在脚本资源下。

<script type="text/javascript">

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function(sender, args){ alert("endRequest"); });

</script>

为什么不使用Page.ClientScript.RegisterStartupScript()来触发它运行,而不是这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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