服务器端调用客户端方法

多好用的两个方法呀:
RegisterStartupScript(key, script)
RegisterClientScriptBlock(key, script)


  这两个方法都接受两个字符串作为输入。第二个参数 script 是要插入到页面中的客户端脚本,包括 <script> 的起始标记和终止标记。第一个参数 key 是插入的客户端脚本的唯一标识符。

  这两个方法唯一的不同之处在于从“何处”发送脚本块。RegisterClientScriptBlock() 在 Web 窗体的开始处(紧接着 <form runat="server"> 标识之后)发送脚本块,而 RegisterStartupScript() 在 Web 窗体的结尾处(在 </form> 标识之前)发送脚本块。

例子:
protected void cBox_Condition_SelectedIndexChanged(object sender, EventArgs e)
    {
        string strDataType = cBox_Condition.SelectedValue.ToString().Split('&')[1].ToString();
        if (strDataType == "DATETIME")
            this.Page.RegisterStartupScript("key", "<script>ShowDateTimeBtn();</script>");
        else
            this.Page.RegisterStartupScript("key", "<script>HideDateTimeBtn();</script>");
    }

     function ShowDateTimeBtn()
     {
        prefix = document.getElementById('imgDateTime').style;
        prefix.visibility = "visible";
     }
     function HideDateTimeBtn()
     {
        prefix = document.getElementById('imgDateTime').style;
        prefix.visibility = "hidden";       
     }
原文地址:https://www.cnblogs.com/spymaster/p/661729.html