Ok I have seen this happen to many people. I have read the suggestions and feel I am still missing something. The created imagebuttons do not fire the assigned btnImg_Click method although the page does post back. Here is my code for reference.
public class Navigation : System.Web.UI.UserControl
{
private Security _security;
private PrivilegeDS _privileges;
private void Page_Load(object sender, System.EventArgs e)
{
_security = (Security)HttpContext.Current.Session["SECURITY"];
_privileges = _security.GetUserPriviledges();
createNavigation();
}
private void createNavigation()
{
foreach(PrivilegeDS.tblPrivilegeRow privilegeDR in _privileges.tblPrivilege)
{
ImageButton btnImg = new ImageButton();
btnImg.ImageUrl = Config.RetrieveConfigSetting("WEB.ImagePath.Nav") + privilegeDR.vchrPrivilege.ToString() + ".gif";
btnImg.CommandArgument = privilegeDR.vchrControl.ToString();
btnImg.CommandName = "MenuItem";
btnImg.ID = privilegeDR.vchrPrivilege.ToString();
btnImg.Click += new System.Web.UI.ImageClickEventHandler(this.btnImg_Click);
this.Controls.Add(btnImg);
}
}
private void btnImg_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
RaiseBubbleEvent(sender,e);
}
Everything I have read seams to point to the fact that the dynamic controls must be created the same for each post back. These controls must also be created in the Page_Load event or the init.