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";       
         }

  • 相关阅读:
    Android悬浮窗拖动
    git提交错误问题如何解决?
    STM32单片机使用注意事项
    C指针说明
    cygwin注意事项
    关于百度地图的使用问题
    Android GIS osmdroid地图使用
    三个能力构建人生护城河
    浪潮之醒
    MingGW Posix VS Win32
  • 原文地址:https://www.cnblogs.com/hyd309/p/1372577.html
Copyright © 2011-2022 走看看