\");的方式也可以做到向页面写入脚本代码, 但是脚本…","url":"https://www.cnblogs.com/shunyao8210/archive/2011/08/04/2127491.html","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.cnblogs.com/shunyao8210/archive/2011/08/04/2127491.html"},"image":"https://assets.cnblogs.com/logo.svg","publisher":{"@type":"Organization","name":"惯性聚合","logo":{"@type":"ImageObject","url":"https://juhe.plus/apple-touch-icon.png"}},"author":{"@type":"Person","name":"IT爱好者"},"datePublished":"2011-08-04T07:58:00.000Z"}]}
























使用Ajax的方法在后置代码(.cs文件中)向页面写入JavaScript脚本的方法,
虽然Response.Write("<script>脚本内容</script>");的方式也可以做到向页面写入脚本代码,
但是脚本输出的内容多在网页显示的最上方,用以下方法可以将脚本内容写在你想要的任意地方。
ClientScriptManager cs = this.ClientScript;
cs.RegisterArrayDeclaration("Hello", "1, 2, 3");
cs.RegisterClientScriptBlock(this.GetType(), "HelloWorld", "function helloWorld(){alert(1);}", true);
cs.RegisterClientScriptInclude("HelloWorld", "HelloWorld.js");
cs.RegisterExpandoAttribute(this.Button1.ClientID, "Hello", "World");
cs.RegisterHiddenField("hello", "world");
cs.RegisterOnSubmitStatement(this.GetType(), "HelloWorld", "return window.confirm('Do you really want to submit the form?')");
cs.RegisterStartupScript(this.GetType(), "HelloWorld", "<script>alert('The page has loaded!')</script>");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。