User Control Not Fired in ASP.NET 2.0
I was planning to use user controls to handle page navigation. If a control is not related to any click events, the control works fine. However, if a user control requires to fire an event, such as click. The event is never fired. The following is a simple user control code:
<%@ Control Language="C#" ClassName="TestUserControl" %>
<script lang="C#" runat="server" >
public void imgTest1_Click(object sender, EventArgs e)
{
txtTest1.Text = "HI there";
}
</script>
<asp:TextBox ID="txtTest1" runat="server" />
<asp:ImageButton ID="imgTest1" ImageUrl="~\Images\PageSize.gif" OnClick="imgTest1_Click" runat="server" />
The way to load the control is control as below:
workPage = LoadControl(ctlurl);
this.WorkArea.Controls.Add(workPage);
where WorkArea is my placeholder in my web page and ctlurl is pointed to the file path of my user control. If I click the image button, it looks like the page was posted back but displays nothing (blank). Can anyone provide any clues why an event does not fire in a user control. I have tried all combinations of "Reference" directive, ClassName in the User Control, programatically add the event in OnInit. But none is working. I know I must miss a simple hook somewhere??????
Thanks for your help!
Jwang
|