如何从母版页调用 javascript?
我正在尝试从母版页调用 javascript 警报,其中我有一个更新面板。其中有一个按钮和一个文本框。
我需要在单击母版页中的按钮时调用警报。到目前为止,它似乎不起作用。请帮忙。
Page.ClientScript.RegisterStartupScript
(this.GetType(), "alert", "invokeMeMaster();", true);
这是我在按钮单击中写的内容。 invokerMEMaster 仅包含一条警报消息。我需要在单击警报的“确定”按钮时重新加载页面。我怎样才能做到这一点?
I'm trying to call a javascript alert from a master page, where i got an update panel. Within that a button and a text box.
I need to call the alert on clicking the button in my master page. So far it seems not working. Please help.
Page.ClientScript.RegisterStartupScript
(this.GetType(), "alert", "invokeMeMaster();", true);
This is what i wrote in my button click. invokerMEMaster include just an alert message.I need to reload the page on the ok button click of the alert. How can i do that as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更新面板会在回发时清除 javascript 代码,因此请尝试将此代码放在标题上。
Update Panel clears javascript code when Postback so try to put this code on the header.
您需要一个 ScriptManagerProxy,其中 ScriptManager 驻留在您的内容页面中
You need a ScriptManagerProxy, with the ScriptManager residing in your content page
如果我可以猜到你的问题(心理调试):当更新面板更新时,javascript不会在你的页面上渲染或触发。
尝试像在更新面板中一样注册您的 javascript:
If I may guess your problem (psychic debugging): When the update panel updates the javascript is not rendered of fired on your page.
Try to register your javascript like in the update panel:
如果我正确理解你的问题,你的内容页面中有一个 JS 函数需要从母版页调用?
我要做的是将隐藏的输入控件和警报功能添加到您的母版页:
然后您可以从内容页更改输入控件的值:
然后只需让母版页中的按钮调用位于的“AlertMe”功能在母版页中。
If I understand your question correctly you have a JS function in a content page that needs to be called from the master page?
What I would do is add a hidden input control and an alert function to your master page:
You could then change the value of the input control from a content page:
Then just have the button in your master page call the "AlertMe" function located in the master page.