• ScriptManager.RegisterStartupScript用法详解


    ScriptManager.RegisterStartupScript(this.Button1, this.GetType(), "alertScript", "window.open('default2.aspx');", true);
    其中第一个参数为要注册脚本的控件ID,试了一下,只要是本页面的就行。
    第二个参数为注册脚本控件类型,是控件还是this的GetType()都可以,typeOf(string)也没问题.
    第三个脚本函数的名字,随便起。
    第四个是脚本内容。
    第五个是标明是否再添加脚本标签,如果第四个参数里包含了 <script> </script>标签,此处则为false,否则为true。
    实例:
     protected void OnEditing(object sender, GridViewEditEventArgs e)
        {
            int id = Int32.Parse(GridView1.Rows[e.NewEditIndex].Cells[1].Text);///得到你要编辑文章的id
                                                                          
            String Url = "AddArticle.aspx?ID=" + id.ToString();////AddArticle.aspx是你要找到编辑的页面
            ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "redirectMe", "location.href='" + Url + "';", true);

    ----------------------------------------

    需要注意的是第4个参数是js脚本内容,每一条语句结束加分号

    注意不是Page.RegisterClientScriptBlock

    ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('提示信息')", true);

  • 相关阅读:
    安装django(使用国内镜像)
    adb工具安装与配置
    mysql
    Charles抓包(iOS的http/https请求)
    selenium+python第一个自动化脚本
    selenium+python环境搭建
    python,你好!
    tjkd-html
    asp
    uglifyjs压缩批处理
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1737183.html
Copyright © 2020-2023  润新知