I have a user control that is being added to another user control. The nested user control is created from a GridView, an image button, and a link button. The nested user control is added to the external control as a collection object based on the results associated with the GridView.
The problem is that my link button does not work. I click on it and the event does not fire. Even adding a breakpoint has not been reached. Since the nested user control has been added several times, I set the image button to have unique identifiers as well as a link button. So far, the image button is working correctly with its JavaScript. The link button should trigger an event in the code behind, but despite all my efforts, I cannot get it to work. I add a link button to the control dynamically. Below is the relevant code that I am using:
public partial class ucCustomerDetails : System.Web.UI.UserControl
{
public event EventHandler ViewAllClicked;
protected override void CreateChildControls( )
{
base.CreateChildControls( );
string strUniqueID = lnkShowAllCust.UniqueID;
strUniqueID = strUniqueID.Replace('$','_');
this.lnkShowAllCust.ID = strUniqueID;
this.lnkShowAllCust.Click += new EventHandler(this.lnkShowAllCust_Click);
this.Controls.Add(lnkShowAllCust);
}
protected override void OnInit (EventArgs e)
{
CreateChildControls( );
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
base.EnsureChildControls( );
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
CreateChildControls( );
}
}
protected void lnkShowAllCust_Click(object sender, EventArgs e)
{
this.OnCustShowAllClicked(new EventArgs ( ));
}
protected virtual void OnCustShowAllClicked(EventArgs args)
{
if (this.ViewAllClicked != null)
{
this.ViewAllClicked(this, args);
}
}
}
I have been dealing with this problem for the last 3 days and have not had success with it, and I really need help.
Can anybody help me?