动态添加用户控件的问题
//ascx
<%@ Control Language= "C# " AutoEventWireup= "true " CodeFile= "WebUserControl.ascx.cs " Inherits= "WebUserControl " %>
<div style= "background-color:Red; width:150px; height:200px; ">
<asp:Button ID= "Button1 " runat= "server " Text= "Button " OnClick= "Button1_Click " />
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox>
</div>
//ascx.cs
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.Visible = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Visible = false;
if (Session[ "OPENED_FOLDER "] != null)
{
Hashtable table = (Hashtable)Session[ "OPENED_FOLDER "];
table.Remove(TextBox1.Text);
}
}
public string Name
{
set { this.TextBox1.Text = value; }
}
}
// aspx
<form id= "form1 " runat= "server ">
<asp:ScriptManager ID= "ScriptManager1 " runat= "server " />
<div>
<asp:Button ID= "Button1 " runat= "server " Text= "Button " OnClick= "Button1_Click " />
</div>
<div id= "Contents " runat= "server "> </div>
</form>
//aspx.cs
public partial class _Default : System.Web.UI.Page
{
string[] names = new string[] { "123 ", "456 ", "789 " };
static int count = 0;
protected void Page_Load(object sender, EventArgs e)
{