• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

View State Causing DataList to disappear

We have a ArrayList that we bind to a DataList, then we create a viewstate that contains the ArrayList.  The final line in the code,

ViewState["ParamArray"] = alParams;

is causing the DataList to disappear when we debug. If I comment out the above line, the DataList appears. Any help is appreciated.

PS - I am kind of new to ASP.NET, so let me apologize if my phrasing or anything is incorrect.
//dlParams is a DataList
 
               ArrayList alParams= new ArrayList();
                
                foreach (string s in _xmlParams)
                {
                    ReportParameters reportParameters = new ReportParameters();
                    
                    etc, etc, etc, etc
 
                    reportParameters.ID = newID;
                    reportParameters.Caption = newTitle;
                    reportParameters.DefaultValue = defval;
 
                    alParams.Add(reportParameters);
                    dlParams.DataSource = alParams;
                    dlParams.DataBind();
 
                    ViewState["ParamArray"] = alParams;
 
                }

Open in new window

0
gregalhaig1
Asked:
gregalhaig1
  • 2
2 Solutions
 
spprivateCommented:
Move the view state commad out of the loop.
Also are you loading this Datalist in the pageload.If so make sure you put a  Postback check in the code
0
 
gregalhaig1Author Commented:
I am loading the DataList on a button_Click event. I did move it outside the loop, but so far same result as before.
0
 
gregalhaig1Author Commented:
I used a session instead and that worked...not the exact way I wanted to do this, but it will work for now. Thanks for help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now