在前台HTML中加入alert或者confirm,相信大家已经非常熟悉并且经常使用:

 <div onclick="alert('hello')">按钮1</div>
<asp:Button ID="Button1" runat="server" Text="按钮2" OnClientClick="return confirm('确定提交吗?')" />

在后台C#中也同样知道如何使用:

using System.Web.UI;

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "id", "<script>alert('hello');</script>", false);

参数介绍:
1)Contrl类型:注册脚本的控件

2)Type类型:注册脚本控件类型

3)string类型:标识脚本块的唯一键

4)string类型:发送到客户端的脚本的内容

5)bool类型:是否添加<script></script>标签

如果经常使用,或多次使用,那就可以写成一个方法:

public void alertMsg(string msg)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "<script>alert('" + msg + "');</script>", false);
}

或者,就封装一下它吧……

通过使用ScriptManager.RegisterStartupScript,呈现后台多次使用alert方法的更多相关文章

  1. System.Web.UI.ScriptManager.RegisterStartupScript(语句末尾加分号,不然可能会造成语句不执行)

    System.Web.UI.ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "testKey", &q ...

  2. ScriptManager.RegisterStartupScript失效的解决方案

    在项目中一个页面使用System.Web.UI.ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "success ...

  3. C#后台无刷新页面弹出alert方法

    原文发布时间为:2009-05-17 -- 来源于本人的百度文章 [由搬家工具导入] 无刷新弹出警告:        ScriptManager.RegisterStartupScript(this. ...

  4. ScriptManager.RegisterStartupScript方法和Page.ClientScript.RegisterStartupScript() 区别

    ScriptManager.RegisterStartupScript方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartu ...

  5. JavaScript 之 ScriptManager.RegisterStartupScript的应用

    如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartupScript(Page.GetType(), "", ...

  6. 关于ScriptManager.RegisterStartupScript 摘录

    //ScriptManager.RegisterStartupScript 方法 (Control, Type, String, String, Boolean) public static void ...

  7. ScriptManager.RegisterStartupScript

    如果页面中不用Ajax,cs中运行某段js代码方式可以是:Page.ClientScript.RegisterStartupScript(Page.GetType(), "", & ...

  8. (转)ScriptManager.RegisterStartupScript方法和Page.ClientScript.RegisterStartupScript() 方法

    ScriptManager.RegisterStartupScript方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartu ...

  9. ScriptManager.RegisterStartupScript()方法和Page.ClientScript.RegisterStartupScript() 方法详解

    ScriptManager.RegisterStartupScript()方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStar ...

随机推荐

  1. HM中字典编码分析

    LZ77算法基本过程 http://jpkc.zust.edu.cn/2007/dmt/course/MMT03_05_2.htm LZ77压缩算法详解 http://wenku.baidu.com/ ...

  2. POJ水题 1298

    #include "stdafx.h" #include <iostream> #include <string> using namespace std; ...

  3. 日期操作类--DateFormat类

    简单的DateFormat格式化编码 时间模式字符串用来指定时间格式.在此模式中,所有的ASCII字母被保留为模式字母,定义如下: 字母 描述 示例 G 纪元标记 AD y 四位年份 2001 M 月 ...

  4. PowerDesigner使用教程|使用方法

    PowerDesigner安装方法:  http://dev.firnow.com/course/3_program/java/javajs/20090908/174375.html 安装完这2个软件 ...

  5. 初学java之JFrame窗口模式

    package project; import javax.swing.*; import java.awt.*; public class test { public static void mai ...

  6. Excepion

    异常:就是程序在运行时出现不正常的情况. 异常由来:问题也就是现实生活中一个具体的食物,也可以通过java的类的形式进行秒速.并封装成对象.其实就是java对不正常情况进行毛素后的对象体现. 对于问题 ...

  7. 聚类算法:K-means 算法(k均值算法)

    k-means算法:      第一步:选$K$个初始聚类中心,$z_1(1),z_2(1),\cdots,z_k(1)$,其中括号内的序号为寻找聚类中心的迭代运算的次序号. 聚类中心的向量值可任意设 ...

  8. 读《程序员的SQL金典》[1]--基础数据检索

    前言 <程序员的SQL金典>这本书是杨中科老师的,拜读了一下,简单做了读书笔记供以后翻阅.仅供学习分享,要想细读的话推荐购买原版呀! 这次读书的时候用了新的办法把看书计划进行了量化,虽然简 ...

  9. json小例子

    <!doctype html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  10. 在vim中执行外部命令

    11.7.5  在Vim编辑器中执行Shell命令 有时需要在Vim编辑器中执行Shell命令,例如需要验证一个Shell命令是否正确,以便写入脚本中:需要在文件中引用某个Shell命令的输入等.本小 ...