UpdatePanel 更新后注册动态 javascript

发布于 2024-07-12 10:59:51 字数 415 浏览 4 评论 0原文

我有一个带有动态创建的 javascript 的页面(该脚本实际上非常静态,但其变量的值是根据用户输入填充的)。

结果和接受用户输入的控件位于 UpdatePanel 内,它会根据某些用户输入进行自我更新。 其中一些用户输入会导致我之前提到的变量发生变化,因此我需要注册一个新的 JavaScript。

当然,问题是只有更新面板得到更新,并且脚本在更新面板之外注册,因此不会添加新脚本。

您认为现在的最佳做法是什么? 我可以通过让这个脚本(和变量)存在于 updatepanel 内来解决这个问题,或者我可以确保在需要发布新的 javascript 时页面完全重新加载? 我页面上已有的 ScriptManager 可能可以帮助我解决这个问题...

所以我正在寻找有类似问题并以良好方式解决它们的人,或者只是有一些好主意的人:)

I have a page with a dynamicly created javascript (the script is pretty static really, but the value of its variables are filled based on user input).

The result and the controls to take user input is inside an UpdatePanel which updates itself on certain user intputs. Some of these userinputs cause changes in the variables i spoke of earlier so i need to register a new javascript.

The problem ofcourse is that only the updatepanel gets updated and the scripts are registred outside the update panel so no new scripts are added.

What do you think would be best practice now? I could solve this by letting this script (and variables) live inside the updatepanel or i could make sure the page is fully reloaded when the need for posting a new javascript arises? The ScriptManager that i already have on the page might be able to help me with this...

So i'm looking for someone who either had similar problems and solved them in a nice way, or just someone with some bright ideas :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

节枝 2024-07-19 10:59:51

我使用 ScriptManager.RegisterStartupScript 的运气比使用 ScriptManager.RegisterClientScriptBlock 的运气要好。 你可以尝试一下。

I've had better luck with ScriptManager.RegisterStartupScript than I did with ScriptManager.RegisterClientScriptBlock. You might give that a shot.

又爬满兰若 2024-07-19 10:59:51

为什么不直接将变量放在更新面板中,或者让 JavaScript 通过 DOM 获取值?

Why not just put the variables inside the update panel, or have the JavaScript get the values through the DOM?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文