部分渲染后 JavaScript 不执行
我有一个最初隐藏的 asp.net 面板,单击按钮时显示。该面板内有 javascript,在面板设置为可见后它不会执行。我可以看到 javascript 函数在页面上输出,但没有被调用。我该怎么做才能调用该函数?这是一个例子:
<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>
I have a asp.net panel that is initially hidden and is shown when a button is clicked. There is javascript inside that panel and it doesn't execute after the panel is set to be visible. I can see that javascript function gets outputted on page but it is not called. 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能希望有某种结束请求方法,每当调用 ajax 方法时都会调用该方法。这必须位于脚本资源下。
You'll probably want to have some sort of end request method that gets called whenever an ajax method is called. this would have to be under the script resource.
与其这样做,为什么不使用 Page.ClientScript.RegisterStartupScript()l 来触发它运行。
Rather than doing that, why not use
Page.ClientScript.RegisterStartupScript()
l to trigger it to run.