从服务器端向页面中发送javascript代码

Posted on 2007-04-28 17:23  ant-boss  阅读(172)  评论(0)    收藏  举报
protected void Button1_Click(object sender, EventArgs e)
 {
  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.RegisterClientScriptResource(
  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>");
 }