RegisterStartupScript和RegisterClientScriptBlock的区别

     1、  //注册到 <form> 尾部 ,HTML元素已加载完毕
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "age1", "Test('" + tbAge.ClientID + "');", true);

    2、 //注册到<form> 头部 ,此时HTML还未加载!
           //js会报 缺少对象
           this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "age2", "Test('" + tbAge.ClientID + "');", true);

      3、
   protected void BtnTest_Click(object sender, EventArgs e) { //注册到 <form> 尾部 ,HTML元素已加载完毕 //this.Page.ClientScript.RegisterStartupScript(this.GetType(), "age1", "Test('" + tbAge.ClientID + "');", true); //UpdatePanel 是用ajax后用上面的没有效果 ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "age1", "Test('" + tbAge.ClientID + "');", true); } protected void BtnTest2_Click(object sender, EventArgs e) { //注册到<form> 头部 ,此时HTML还未加载! //js会报 缺少对象 //this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "age2", "Test('" + tbAge.ClientID + "');", true); //使用ajax的UpdatePanel 后 //页面上的this.UpdatePanel1控件ID ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, typeof(Page), "key1", "Test('" + tbAge.ClientID + "');", true); }
原文地址:https://www.cnblogs.com/qiuyueguangxuan/p/4183960.html