locked
ASP.NET Mobile - a code error of POSTBACK Asp.Net Mobile / ObjectList and DataBind RRS feed

  • Question

  • User741646601 posted
    Hello staff, to run my application Asp.Net Mobile, with the Object - Object List, gathering data from a DataBind, the following occurs

        A) The application will run it performs and displays the list of items in Object List normally and click it vai him for the part of the item or record details of the item normally, the problem is that when you click on 'back' or command 'Return to list' he accuses the following error of postback<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
    <o:p> </o:p>

    Erro de Servidor no Aplicativo '/VS2005/NET2.0/AspNetMobile/objectlistcsharp'.


    Invalid posted data for current ObjectList ViewMode.  (The ObjectList may have been databound on postback during Page_Load, resetting the ViewMode.  Call DataBind in Page_Load only if IsPostBack is false.) <o:p></o:p>

    Description: There was an exception untreated during the implementation of the current web request Examine the tracking of battery for more information about the error and which originated in the code.<o:p></o:p>

    Details of the Exception: System.Exception: Invalid posted data for current ObjectList ViewMode.  (The ObjectList may have been databound on postback during Page_Load, resetting the ViewMode.  Call DataBind in Page_Load only if IsPostBack is false.)

    Error of Origin: <o:p></o:p>

    Unhandled exception was generated during the execution of the current web request The information related to the origin and the place of exception can be identified using the tracking of Cell exception below<o:p></o:p>

    . <o:p></o:p>

    Tracking Cell: <o:p></o:p>
    <o:p> </o:p>
    [Exception: Invalid posted data for current ObjectList ViewMode.  (The ObjectList may have been databound on postback during Page_Load, resetting the ViewMode.  Call DataBind in Page_Load only if IsPostBack is false.)]<o:p></o:p>
       System.Web.UI.MobileControls.Adapters.HtmlObjectListAdapter.HandlePostBackEvent(String eventArgument) +343<o:p></o:p>
       System.Web.UI.MobileControls.ObjectList.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +24<o:p></o:p>
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11<o:p></o:p>
       System.Web.UI.MobileControls.MobilePage.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +77<o:p></o:p>
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177<o:p></o:p>
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746<o:p></o:p>
    <o:p> </o:p>Below I am sending the code-behind of my application and the source of pagina.Se pd someone help me now thank you<o:p></o:p><o:p> </o:p>

    CODE-BEHIND

    <o:p> </o:p>using System;<o:p></o:p>using System.Collections;<o:p></o:p>using System.ComponentModel;<o:p></o:p>using System.Data;<o:p></o:p>using System.Drawing;<o:p></o:p>using System.Web;<o:p></o:p>using System.Web.Mobile;<o:p></o:p>using System.Web.SessionState;<o:p></o:p>using System.Web.UI;<o:p></o:p>using System.Web.UI.MobileControls;<o:p></o:p>using System.Web.UI.WebControls;<o:p></o:p>using System.Web.UI.HtmlControls;<o:p></o:p>using System.Data.OleDb;<o:p></o:p><o:p> </o:p>public partial class _Default : System.Web.UI.MobileControls.MobilePage<o:p></o:p>{<o:p></o:p>    protected void Page_Load(object sender, EventArgs e)<o:p></o:p>    {<o:p></o:p>                <o:p></o:p>              OleDbConnection DBConn; <o:p></o:p>              OleDbDataAdapter DBCommand; <o:p></o:p>              DataSet DSPageData = new DataSet(); <o:p></o:p>              DBConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "DATA SOURCE=" + Server.MapPath("EmployeeDatabase.mdb;")); <o:p></o:p>            DBCommand = new OleDbDataAdapter("Select * " + "From Employee " + "Order By FirstName", DBConn); <o:p></o:p>              DBCommand.Fill(DSPageData, "Emps");<o:p></o:p>            ObjectList1.DataSource = DSPageData.Tables["Emps"].DefaultView;<o:p></o:p>              ObjectList1.DataBind(); <o:p></o:p><o:p> </o:p>    }<o:p></o:p>}<o:p></o:p><o:p> </o:p>

    Source.aspx

    <o:p> </o:p><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><o:p></o:p><%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %><o:p></o:p><o:p> </o:p><html xmlns="http://www.w3.org/1999/xhtml" ><o:p></o:p><body><o:p></o:p>    <mobile:Form id="Form1" runat="server"><o:p></o:p>        <mobile:ObjectList ID="ObjectList1" Runat="server" CommandStyle-StyleReference="subcommand"<o:p></o:p>            LabelStyle-StyleReference="title"><o:p></o:p>        </mobile:ObjectList><o:p></o:p><o:p> </o:p>    </mobile:Form><o:p></o:p></body><o:p></o:p></html><o:p></o:p><o:p> </o:p>Translated from Portuguese into English by Google<o:p></o:p><o:p> </o:p>

     

    Sunday, July 13, 2008 8:09 PM

Answers

  • User-1071856410 posted

    bind data only if it is not a postback as given below.

    It will solve your issue.

    .


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OleDbConnection DBConn; OleDbDataAdapter DBCommand;
                DataSet DSPageData = new DataSet();
                DBConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "DATA SOURCE=" + Server.MapPath("EmployeeDatabase.mdb;"));    DBCommand = new OleDbDataAdapter("Select * " + "From Employee " + "Order By FirstName", DBConn);
                DBCommand.Fill(DSPageData, "Emps");
                ObjectList1.DataSource = DSPageData.Tables["Emps"].DefaultView;
                ObjectList1.DataBind();
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 23, 2008 7:06 AM

All replies

  • User-1071856410 posted

    bind data only if it is not a postback as given below.

    It will solve your issue.

    .


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OleDbConnection DBConn; OleDbDataAdapter DBCommand;
                DataSet DSPageData = new DataSet();
                DBConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "DATA SOURCE=" + Server.MapPath("EmployeeDatabase.mdb;"));    DBCommand = new OleDbDataAdapter("Select * " + "From Employee " + "Order By FirstName", DBConn);
                DBCommand.Fill(DSPageData, "Emps");
                ObjectList1.DataSource = DSPageData.Tables["Emps"].DefaultView;
                ObjectList1.DataBind();
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 23, 2008 7:06 AM
  • User741646601 posted
    Thanks already resolved

    Translated from Portuguese to English by Google
    Tuesday, September 23, 2008 11:56 AM