M
Mike Collins
In my web application, I have a treeview. Based on which node is clicked, I
am loading user controls. Currently, I am loading my controls in the
SelectedNodeChanged event, but I want to load the user controls in OnInit so
I can have them in the ViewState, but the treeview is not created yet. Is
this possible, or do I need to keep loading my user controls after the OnInit
event?
Example of what I am doing now:
protected void tvAccountSetup_SelectedNodeChanged(object sender, EventArgs e)
{
AddControl(@"UserControls\" + tvAccountSetup.ID.Substring(2) + @"\" +
tvAccountSetup.SelectedValue + ".ascx");
}
private void AddControl(string control)
{
//In case the page cannot be found, with this code in a try catch, it will
not error.
try
{
PlaceHolder1.Controls.Clear();
Control c = Page.LoadControl(control);
PlaceHolder1.Controls.Add(c);
}
catch
{
}
am loading user controls. Currently, I am loading my controls in the
SelectedNodeChanged event, but I want to load the user controls in OnInit so
I can have them in the ViewState, but the treeview is not created yet. Is
this possible, or do I need to keep loading my user controls after the OnInit
event?
Example of what I am doing now:
protected void tvAccountSetup_SelectedNodeChanged(object sender, EventArgs e)
{
AddControl(@"UserControls\" + tvAccountSetup.ID.Substring(2) + @"\" +
tvAccountSetup.SelectedValue + ".ascx");
}
private void AddControl(string control)
{
//In case the page cannot be found, with this code in a try catch, it will
not error.
try
{
PlaceHolder1.Controls.Clear();
Control c = Page.LoadControl(control);
PlaceHolder1.Controls.Add(c);
}
catch
{
}