zoukankan      html  css  js  c++  java
  • 第二次动态产生铵钮的Click事件

    网页在第一次运行时,它动态产生了一个铵钮,此称为第一个铵钮,当用户用mouse点击这个铵钮时,会动态产生另一个铵钮,此称为第二个铵钮,当用户再用mouse点击第二个铵钮时,系统将处理另外的事情。此博文是实再第二个铵钮的Click事件。首先看看效果:

     

    .aspx:

    View Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">   
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <fieldset>
                        <legend>网页运行时动态产生的Button</legend>
                        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                    </fieldset>
                    <fieldset>
                        <legend>用Mouse点击第一个Button产生的Button</legend>
                        <asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
                    </fieldset>
                </ContentTemplate>
            </asp:UpdatePanel>   
        </form>
    </body>
    </html>

     

    .apsx.cs:

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Insus.NET;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button Button1 = new Button();
            Button1.Text = "I was the first button";
            Button1.Click += Button1_Click;
            this.PlaceHolder1.Controls.Add(Button1);

            if (ViewState["Click"] != null && (bool)ViewState["Click"])
                GenerateButtonControl();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            if (ViewState["Click"] == null)
            {
                ViewState["Click"] = true;
                GenerateButtonControl();
            }
        }

        private void GenerateButtonControl()
        {
            Button Button2 = new Button();
            Button2.Text = "I was the second button";
            Button2.Click += new EventHandler(Button2_Click);
            this.PlaceHolder2.Controls.Add(Button2);
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            InsusJavascriptUtility objJs = new InsusJavascriptUtility();
            objJs.JsAlert("Hi, Good evening!");     
        }
    }


     

  • 相关阅读:
    AGC012
    AGC010
    AGC010
    AGC010
    AGC010
    BZOJ2120
    python_way,day8 面向对象【多态、成员--字段 方法 属性、成员修饰符、特殊成员、异常处理、设计模式之单例模式、模块:isinstance、issubclass】
    python_way ,day7 面向对象 (初级篇)
    python_way.day7 模块(configparser,xml,shutil,subprocess)、面向对象(上)(创建类,类的构成,函数式编程与面向对象编程的选择,类的继承)
    python_way ,day5 模块,模块3 ,双层装饰器,字符串格式化,生成器,递归,模块倒入,第三方模块倒入,序列化反序列化,日志处理
  • 原文地址:https://www.cnblogs.com/insus/p/2717420.html
Copyright © 2011-2022 走看看