I have a nested UserControl
(this control is dynamicall loaded by another UserControl
that is dynamically loaded by an aspx page inside a MasterPage) in which I would like to use a LinkButton
and the OnCommand
Event.
This button must be added to some panel, so I hooked up to the OnLoad
event of the panel (it needs to be created before events are fired in the lifecycle) :
protected void PatentAssignee_Load(object sender, EventArgs e) {
Label label = (Label)sender;
LinkButton link = new LinkButton();
link.Text = name;
link.Command += Link_OnCommand;
link.CommandArgument = "argument";
link.ID = "someID";
label.Controls.Add(link)
}
protected void Link_OnCommand(object sender, CommandEventArgs e) {
Response.Write(e.CommandArgument);
}
But I can't get the Link_OnCommand method to be called. One more thing that my be relevant to this problem : the UserControl is inside an UpdatePanel. I also tried to make the link trigger a full postback :
ScriptManager s = (ScriptManager)this.Page.Master.FindControl("__scriptManager");
s.RegisterPostBackControl(link);
... but it doesn't change much, the page is fully reloaded but no event is fired.
EDIT: As requested in the comments, here are more details about the nesting :
MasterPage
PlaceHolder
Page
UpdatePanel
UserControl1
FormView
PlaceHolder
UserControl2
LinkButton
This means that UserControl2
is dynamically loaded.