using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }

    //插入到文档的末端
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!this.Page.ClientScript.IsStartupScriptRegistered("key1"))
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "key1", "<script language=javascript>alert('" + "ok1" + "')</script>");
        }

    }

   //插入到文档的顶端(实践证明,不论是否采用判断,都会弹出对话框。估计是页面发回服务器后,再发来,脚本就丢失了)
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (!this.Page.ClientScript.IsClientScriptBlockRegistered("key2"))
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "key2", "<script language=javascript>alert('" + "ok2" + "')</script>");
        }
    }
}

 

posted on 2019-01-30 23:33  qqhfeng16  阅读(144)  评论(0编辑  收藏  举报