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>");
            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";       
         }
  • 相关阅读:
    权限管理
    书城项目第五阶段---book表的curd
    大话设计模式学习
    数据绑定流程分析
    GO 解决使用bee工具,报 bash: bee: command not found
    VScode插件:Todo Tree
    ant design pro如何实现分步表单时,返回上一步值依然被保存
    React开发流程
    为什么函数式组件没有生命周期?
    html2canvas@^1.0.0-rc.1
  • 原文地址:https://www.cnblogs.com/spymaster/p/661729.html
Copyright © 2011-2022 走看看