【发布时间】:2011-06-02 21:44:10
【问题描述】:
我有 UserControl:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wControl1.ascx.cs" Inherits="TestProjectSite.wControl1" %>
<asp:Button ID="Button12" runat="server" Text="Button12" onclick="Button12_Click" OnClientClick="true" />
C#:
public string Name { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Button12.Text = Name;
}
protected void Button12_Click(object sender, EventArgs e)
{
//...
//The problem is here... it doesn't get inside...
}
和页面.ASPX:
<p>
<asp:TextBox ID="TextBox1" Width="500" Height="34" runat="server"
Font-Size="22px"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Height="32" Text="חפש..."
OnClick="Button2_Click" Font-Size="20px" />
</p>
<P>
<asp:PlaceHolder ID="plhItems" runat="server" >
</P>
C#:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
Func(TextBox1.Text);
}
public void Func(string text)
{
wControl1 eControl = (wControl1)Page.LoadControl("wControl1.ascx");
eControl.Name = text;
plhItems.Controls.Add(eControl);
}
问题出在 Button12_Click 事件中。
当我按下按钮 (Button2) 时,将创建控件的实例。 但是当我再次按下 UserControl(wControl) 的按钮时,他不会去 codeBehind eventClick.... 只有当我在 Page_Load 事件中使用 userControl 的创建时它才会好的.. 但我想要它来自事件Button2...
我能做什么??
谢谢..
【问题讨论】:
标签: c# asp.net events user-controls onclick