S
Shawn Meyer
Im sure this has been discussed here before but I have had no luck finding
an answer.
I am trying to create a simple web app, with a navigation on one side that
will load up pages on the other. The nav side is a custom control, that has
an event that fires upon click, and then sets a selectedindex. I am using
the selected index to determine what ascx page to load up. I created a
"LoadControl" function to load the ascx page and add it to the placeholder
controls. This function gets called when the selectedindexchaged event
fires (which is mapped to the nav control), and a viewstate variable gets
set. The PostBack function checks for this variable and if there, calls the
loadcontrol again.
** The ascx pages that I load have post back items on them, such as a
textboxs and submit button.
The nav events fire, which loads the ascx correctly, however the first time
I hit submit button, the button click event (on the loaded ascx page) does
not fire. Every time after that the event fires properly.
From what I have read, when you load an ascx after the after the pageload
has executed (ie. due to a event ) your events on the loaded page will not
work properly because they were not loaded during pageload. And after the
second click it worked because of my call to LoadControl in the postback.
Some people have suggested to load all of your pages, and toggle visibility,
but this really isn't an option since I plan on having a large number of
pages on the site.
Is there any way to make this work? Attached is the code snips.
-- Page load
<snip>
if ( isPostBack )
{
if (ViewState["Control1"] != null )
{
LoadControl();
}
}
<snip>
private System.Web.UI.Control home_control;
private void LoadControl()
{
switch (FooterPanelBar.SelectedIndex)
{
case 0:
home_control = LoadControl("a.ascx");
PlaceHolder_Body.Controls.Add(home_control);
break;
case 1:
home_control = LoadControl("b.ascx");
PlaceHolder_Body.Controls.Add(home_control);
break;
}
}
private void FooterPanelBar_SelectedIndexChanged(object sender, EventArgs e)
{
PlaceHolder_Body.Controls.Clear(); // clear out the loaded one to
perform switch to new ascx
LoadControl();
ViewState["Control1"] = "Control1";
}
Thanks, Shawn Meyer
an answer.
I am trying to create a simple web app, with a navigation on one side that
will load up pages on the other. The nav side is a custom control, that has
an event that fires upon click, and then sets a selectedindex. I am using
the selected index to determine what ascx page to load up. I created a
"LoadControl" function to load the ascx page and add it to the placeholder
controls. This function gets called when the selectedindexchaged event
fires (which is mapped to the nav control), and a viewstate variable gets
set. The PostBack function checks for this variable and if there, calls the
loadcontrol again.
** The ascx pages that I load have post back items on them, such as a
textboxs and submit button.
The nav events fire, which loads the ascx correctly, however the first time
I hit submit button, the button click event (on the loaded ascx page) does
not fire. Every time after that the event fires properly.
From what I have read, when you load an ascx after the after the pageload
has executed (ie. due to a event ) your events on the loaded page will not
work properly because they were not loaded during pageload. And after the
second click it worked because of my call to LoadControl in the postback.
Some people have suggested to load all of your pages, and toggle visibility,
but this really isn't an option since I plan on having a large number of
pages on the site.
Is there any way to make this work? Attached is the code snips.
-- Page load
<snip>
if ( isPostBack )
{
if (ViewState["Control1"] != null )
{
LoadControl();
}
}
<snip>
private System.Web.UI.Control home_control;
private void LoadControl()
{
switch (FooterPanelBar.SelectedIndex)
{
case 0:
home_control = LoadControl("a.ascx");
PlaceHolder_Body.Controls.Add(home_control);
break;
case 1:
home_control = LoadControl("b.ascx");
PlaceHolder_Body.Controls.Add(home_control);
break;
}
}
private void FooterPanelBar_SelectedIndexChanged(object sender, EventArgs e)
{
PlaceHolder_Body.Controls.Clear(); // clear out the loaded one to
perform switch to new ascx
LoadControl();
ViewState["Control1"] = "Control1";
}
Thanks, Shawn Meyer