Solved

EnableViewState error

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
jQuery or Javascript animation question 6 73
replace quotes with UTF-8 character 38 115
Question on web subscription for apps 3 122
WCAG audit tools 1 122
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…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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