Solved

EnableViewState error

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now