ASP.NET 在更新面板中嵌套的用户控件中注入 javascript
我正在尝试在更新面板的异步回发期间通过 Page.LoadControl 方法将带有用户 Web 控件的 JavaScript 代码加载到页面中。
我已经尝试了专门针对该场景设计的脚本管理器方法,但是 javascript 没有返回给用户。
为了更好地解释我的场景:
母版页具有脚本管理器,并且一个页面在异步回发期间通过 Page.LoadControl 方法加载用户控件。 自定义控件将 JavaScript 注入到预渲染事件处理程序中。 这是注入js的时间问题还是根本不可能这样做?
I'm trying to load javascript code with a user web control into a page via a the Page.LoadControl method during an asyncron post back of an update panel.
I've tried the specially for that scenario designed methods of the scriptmanager, but the javascript just doens't get returned to the user.
To explain my scenario a bit better:
Master Page has the script manager and one page loads the user control via Page.LoadControl-method during an async post back. The custom control injects in the pre-render event handler the javascript. Is that a matter of timing to inject the js or is it just not possible to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为此你可以做
HTH
For that you can do
HTH
如果您不想对 JavaScript 进行硬编码,而是从文件中包含它,请调用 ScriptManager.RegisterClientScriptInclude ,然后在 ScriptManager.RegisterStartupScript。
If you don't want to hard-code your JavaScript, but instead include it from a file, call ScriptManager.RegisterClientScriptInclude and then call your initialization function in ScriptManager.RegisterStartupScript.
您尝试过吗?
我们在用户控件中执行此操作,它对我们有用
HTH
Have your tried
We do this in our User Controls and it works for us
HTH
您可以使用 ScriptManager 类的 RegisterStartupScript 方法来注入可执行脚本:
You can use the RegisterStartupScript method of the ScriptManager class to inject executable script:
如果您的控件嵌套在 asp.net 模式弹出窗口中,则将 RegisterStartupScript 放入 Page_PreRender 事件中可能不起作用。 相反,当 IsPostBack = False 时将其放入 Page_Load 中。
Putting the RegisterStartupScript in the Page_PreRender event may not work if your control is nested in an asp.net modal popup. Instead, put it in the Page_Load when IsPostBack = False.