admin管理员组文章数量:1312923
I have a few Database things to read in the Page_Load of my Asp page.
if (xxx == 1)
//Add OnLoad("clock()")
How to do this? How to add a OnLoad-Method for a JavaScript clock in the page load method?
I have a few Database things to read in the Page_Load of my Asp page.
if (xxx == 1)
//Add OnLoad("clock()")
How to do this? How to add a OnLoad-Method for a JavaScript clock in the page load method?
Share Improve this question asked Apr 25, 2011 at 10:45 PassionateDeveloperPassionateDeveloper 15.2k35 gold badges111 silver badges190 bronze badges3 Answers
Reset to default 41st Make your body tag a servercontrol
<body runat="server" id="BodyTag">
2nd reference it like
if (xxx == 1)
BodyTag.Attributes.Add("onload", "clock()");
Use the RegisterClientScriptBlock
method to add client code to the page:
Page.ClientScript.RegisterClientScriptBlock(
this.GetType(),
"onload",
"window.onload = function(){ clock(); }",
true
);
Register a startup script in the Page_Load
. ClientScriptManager (http://msdn.microsoft./en-us/library/z9h4dk8y.aspx) or ScriptManager (http://msdn.microsoft./en-us/library/bb310408.aspx)... whichever is appropriate.
string clockStuff =
@"function callClockFunction(){
Sys.Application.remove_load(callClockFunction);
clock(); }
Sys.Application.add_load(callClockFunction);";
ScriptManager.RegisterStartupScript(this, this.GetType(), "callClockFunction", clockStuff, true);
本文标签: javascriptAdd OnLoad() in PageLoad()Stack Overflow
版权声明:本文标题:javascript - Add OnLoad() in Page_Load()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741893582a2403444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论