Solved

EnableViewState error

Posted on 2004-10-07
4
483 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
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 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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