Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

EnableViewState error

Posted on 2004-10-07
4
Medium Priority
?
490 Views
Last Modified: 2012-06-22
Experts,
I am developing a .net mobile page. I was getting the error page saying the session expired on the mobile. So for the list box (Mobile:SelectionList) that I am using I set EnableViewState=False to solved the problem.
But now, while using EnableViewState=False , I am getting the following error on any button click (mostly clicking a button second time).  If I took this flag out the page is okay.

Any idea?

Thanks in anticipation

SJ


The error is
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentOutOfRangeException: Index was out of range.  Must be non-negative and less than the size of the collection.
Parameter name: index]
   System.Collections.ArrayList.get_Item(Int32 index) +91
   System.Web.UI.MobileControls.MobileListItemCollection.get_Item(Int32 index) +68
   System.Web.UI.MobileControls.Adapters.HtmlSelectionListAdapter.LoadPostData(String key, NameValueCollection data, Object controlPrivateData, Boolean& dataChanged) +957
   System.Web.UI.MobileControls.SelectionList.System.Web.UI.IpostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +96
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +391
   System.Web.UI.Page.ProcessRequestMain() +621







0
Comment
Question by:SijuJohn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 12266643
post the code for your listBox
0
 

Author Comment

by:SijuJohn
ID: 12274768
YZlat ,

Thanks for thr reply

Following the code that I am using

                        protected void LoadSelectionList(int opt){
                           DataSet ds = new DataSet();
                           ds = LoadDetails(opt);
   
                           SelectionList1.DataSource = ds;
                           SelectionList1.DataValueField = "j_id";
                           SelectionList1.DataBind ();
                        }


                        System.Data.DataSet LoadDetails(int j_JSC_ID) {
                            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\\Copy_Of_Live_DB\\JobDet.mdb";
                            System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);
   
                            string queryString = "SELECT [Jobs].[J_ID] ,j_c_number,j_fault_line1 FROM [Jobs] WHERE ([Jobs].[J_JSC_ID] = " +
                   "@J_JSC_ID)";
                            System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
                            dbCommand.CommandText = queryString;
                            dbCommand.Connection = dbConnection;
   
                            System.Data.IDataParameter dbParam_j_JSC_ID = new System.Data.OleDb.OleDbParameter();
                            dbParam_j_JSC_ID.ParameterName = "@J_JSC_ID";
                            dbParam_j_JSC_ID.Value = j_JSC_ID;
                            dbParam_j_JSC_ID.DbType = System.Data.DbType.Int32;
                            dbCommand.Parameters.Add(dbParam_j_JSC_ID);
   
                            System.Data.IDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
                            dataAdapter.SelectCommand = dbCommand;
                            System.Data.DataSet dataSet = new System.Data.DataSet();
                            dataAdapter.Fill(dataSet);
   
                            return dataSet;
                        }
0
 
LVL 8

Accepted Solution

by:
tomvergote earned 750 total points
ID: 12275914
I take it your don't use if (!Page.IsPostback()) in your onload.
After you clicked the button, the onload resets/refills the dropdown. Then in the onclick you are trying to access the selecteditem, but since the ddl got repopulated there is no selecteditem. (or something along those lines)

Either use viewstate to make sure there is a selected item, or use appropriate if not ispostback code in your onload
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question