ListBox Loses ViewState

Discussion in 'ASP .Net Web Controls' started by Andrew, Jul 22, 2004.

  1. Andrew

    Andrew Guest

    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;
    }
    --
    "It is not the critic who counts, not the man who points out how the strong man stumbled, or where the doer of deeds could have done better. The credit belongs to the man who is actually in the arena"
    Andrew, Jul 22, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Bittner

    Contact form with file upload loses viewstate

    Benjamin Bittner, Dec 10, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,577
    Benjamin Bittner
    Dec 10, 2004
  2. Janaka

    Listbox loses values

    Janaka, Feb 14, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,858
    Janaka
    Feb 15, 2005
  3. Tumurbaatar S.

    ViewState error and DataGrid loses its content

    Tumurbaatar S., Jan 25, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    420
    Tumurbaatar S.
    Jan 25, 2006
  4. Spam Catcher
    Replies:
    0
    Views:
    584
    Spam Catcher
    Feb 18, 2006
  5. matt
    Replies:
    1
    Views:
    224
    Hidetoshi NAGAI
    Jun 10, 2004
Loading...

Share This Page