G
Guest
I'm loading a user control using the method:
uc = Page.LoadControl("../UC.ascx");
Afterwards I set some variables in uc. For instance
uc.Count = 10;
Count is the number of link buttons which should be generated in uc. The
Pre_Render method of uc looks like this:
private void UC_PreRender(object sender, System.EventArgs e)
{
for(int i = 0; i < Count; i++)
{
LinkButton lb = new LinkButton();
lb.Text = ""+i;
lb.Click += new EventHandler(lbClick);
SomePlaceHolder.Controls.Add(lb);
}
}
The code is placed in the PreRender method because i need to be able to set
variable Count before the buttons are created. However it seems that I cannot
cathc any events on buttons which are not added in the Page_Load or before.
How do I solve this problem in a nice way?
If I could only create the usercontrol with some sort of constructer with
some arguments instead of using the LoadControl method, then my problems
would be solved.
Thanks for your help.
Nikolaj
uc = Page.LoadControl("../UC.ascx");
Afterwards I set some variables in uc. For instance
uc.Count = 10;
Count is the number of link buttons which should be generated in uc. The
Pre_Render method of uc looks like this:
private void UC_PreRender(object sender, System.EventArgs e)
{
for(int i = 0; i < Count; i++)
{
LinkButton lb = new LinkButton();
lb.Text = ""+i;
lb.Click += new EventHandler(lbClick);
SomePlaceHolder.Controls.Add(lb);
}
}
The code is placed in the PreRender method because i need to be able to set
variable Count before the buttons are created. However it seems that I cannot
cathc any events on buttons which are not added in the Page_Load or before.
How do I solve this problem in a nice way?
If I could only create the usercontrol with some sort of constructer with
some arguments instead of using the LoadControl method, then my problems
would be solved.
Thanks for your help.
Nikolaj