日期:2014-05-19  浏览次数:20698 次

asp.net中为"动态创建的控件"绑定事件
在线等高手回复!!!!
代码如下:using   System;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;

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

        }
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                Button   b   =   new   Button();
                b.Text   =   "Click ";
                b.Click   +=   new   System.EventHandler(this.ButtonClick);

                Panel1.Controls.Add(b);

                Panel1.Visible   =   true;
        }
   
        public   void   ButtonClick(object   sender,   EventArgs   e)
        {
                Label1.Text   =   "ButtonClick ";
        }
}


<%@   Page   Language= "C# "   AutoEventWireup= "true "   CodeFile= "Button.aspx.cs "   Inherits= "testCase_Button "   %>

<!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> Untitled   Page </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                &nbsp;&nbsp;
                <div   style= "text-align:   center ">
                        <table   style= "width:   340px;   height:   309px ">
                                <tr   align=center>
                                        <td   style= "width:   100px;   height:   4px ">
                                                <asp:Button   ID= "Button1 "   runat= "server "