UpdatePanel中使用脚本文件(ScriptManager.RegisterStartupScript 方法)

来源:互联网 发布:人工智能在汽车的应用 编辑:程序博客网 时间:2024/05/16 04:46

     在UpdatePanel控件中,想弹出一个提示框。我开始时这样写:Response.Write("<script>alert('用户名或密码错误!')</script>")。但是不行。

        后来在网上找了一个方法用:ScriptManager.RegisterStartupScript 方法 (Control, Type, String, String, Boolean)。

         它的作用是:使用 ScriptManager 控件为 UpdatePanel 中的某个控件注册一个启动脚本块,并将该脚本块添加到页面中。

         参数说明:

control
类型:System.Web.UI.Control

正在注册该客户端脚本块的控件。

type
类型:System.Type

该客户端脚本块的类型。通常使用 typeof 运算符 (C#) 或 GetType 运算符 (Visual Basic) 来指定该参数,以检索正在注册该脚本的控件的类型。

key
类型:System.String

该脚本块的唯一标识符。

script
类型:System.String

该脚本。

addScriptTags
类型:System.Boolean

如果用 <script></script> 标记括起该脚本块,则为 true;否则为 false

示例:
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "alert", "<script>alert('用户名或密码错误!')</script>", false);

原创粉丝点击