A
Andrew
I am stuck. I'll try to be descriptive, it's a weird one.
I have a webpage with two placeholders.
One of the UserControls has two ListBoxs, "lstOne" and "lstTwo". lstOne contains eight ListItems or two ListItems, depending upon the values of RadioButtons.
It doesn't happen immediately. When the page loads, lstOne contains eight ListItems. When the RadioButtons are changed, lstOne (correctly) has eight ListItems until it is reloaded. Then it has two. All is well at this point.
When the user selects the first ListItem and clicks an ImageButton, the right UserControl is loaded (it contains a DataGrid). All is well.
When the second ListItem is selected and the ImageButton is clicked, the right UserControl loads a DataGrid. All is well.
Here is the problem: when the first ListItem is selected again and the ImageButton is clicked, and set a breakpoint in lstOne's Page_Load event, the ViewState has been lost!
I don't know what to do. Please help me.
Here are some code snippets:
UserControl Page_Load:
private void Page_Load(object sender, System.EventArgs e)
{
try
{
SecurityCheck();
loadlstTwo();
loadlstOne();
...
In WebForm1.aspx:
private UserControl discoverUC(Type ucTyp, ref PlaceHolder plch)
{
string strTypeName = ucTyp.ToString() + "_ascx";
strTypeName = strTypeName.Replace("WRS.","ASP.");
string strControlName = strTypeName.Remove(0,4).Replace("_ascx",".ascx");
string strControlID = strTypeName.Replace("_ascx","ascx").Replace("ASP.","");
UserControl ucAny = new UserControl();
ucAny = (UserControl)plch.FindControl(strControlID);
if (ucAny == null)
{
ucAny= (UserControl)this.LoadControl(strControlName);
}
return ucAny;
}
I have a webpage with two placeholders.
One of the UserControls has two ListBoxs, "lstOne" and "lstTwo". lstOne contains eight ListItems or two ListItems, depending upon the values of RadioButtons.
It doesn't happen immediately. When the page loads, lstOne contains eight ListItems. When the RadioButtons are changed, lstOne (correctly) has eight ListItems until it is reloaded. Then it has two. All is well at this point.
When the user selects the first ListItem and clicks an ImageButton, the right UserControl is loaded (it contains a DataGrid). All is well.
When the second ListItem is selected and the ImageButton is clicked, the right UserControl loads a DataGrid. All is well.
Here is the problem: when the first ListItem is selected again and the ImageButton is clicked, and set a breakpoint in lstOne's Page_Load event, the ViewState has been lost!
I don't know what to do. Please help me.
Here are some code snippets:
UserControl Page_Load:
private void Page_Load(object sender, System.EventArgs e)
{
try
{
SecurityCheck();
loadlstTwo();
loadlstOne();
...
In WebForm1.aspx:
private UserControl discoverUC(Type ucTyp, ref PlaceHolder plch)
{
string strTypeName = ucTyp.ToString() + "_ascx";
strTypeName = strTypeName.Replace("WRS.","ASP.");
string strControlName = strTypeName.Remove(0,4).Replace("_ascx",".ascx");
string strControlID = strTypeName.Replace("_ascx","ascx").Replace("ASP.","");
UserControl ucAny = new UserControl();
ucAny = (UserControl)plch.FindControl(strControlID);
if (ucAny == null)
{
ucAny= (UserControl)this.LoadControl(strControlName);
}
return ucAny;
}