Solved

EnableViewState error

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

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

729 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