zoukankan      html  css  js  c++  java
  • 服务器端调用客户端方法

     

    多好用的两个方法呀:
    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>");


            this.Page.RegisterStartupScript("key", "<script>Show('" + str + "')</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";       
         }

  • 相关阅读:
    一元多项式乘法
    将博客搬至CSDN
    Tomcat的几种部署方式
    Visual Studio 2012以后无法保存只读文件的问题
    WPF中的Generic.xaml, theme以及custom control
    WPF的页面导航
    WPF MVVM系列文章
    tomcat中同时部署两个项目的问题
    Windows多线程系列
    XML DTD和XML Schema
  • 原文地址:https://www.cnblogs.com/hyd309/p/1372577.html
Copyright © 2011-2022 走看看