Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2004, 07:14 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default datagrid paging error

I have a data grid populated with a dataset and it has paging enabled. i have set the onclick event and it then goes to the next page but when i then click the previous page button it generates the following.

Server Error in '/' Application.
--------------------------------------------------------------------------------

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
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.Web.HttpException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

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:


[HttpException (0x80004005): Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.]
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +189
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +414
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +414
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +414
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +414
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +414
   System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +414
   System.Web.UI.Page.LoadPageViewState() +306
   System.Web.UI.Page.ProcessRequestMain() +423




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

my code is:


<%@ Page Language="VB" Debug="True" %>
<script runat="server">

    'This binds the information to the data grid
    Sub Page_Load()

    'This checks to see if their is a cookie on the viewers system.
    If Request.Cookies("DJUserNameCookie") is nothing Then

    'If there is not one then it sends the person back to the login page.
    Response.Redirect("login.aspx")

    End If

        GridMessages.Datasource() = GetMessages()
        GridMessages.Databind()

    End Sub


            'This is the function that calls for the messages that can then be bound in the page
            'load event.
            Function GetMessages() As System.Data.DataSet
                Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\djguestbook\guestDatabas e.mdb"
                Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

                Dim queryString As String = "SELECT [Messages].* FROM [Messages]"
                Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
                dbCommand.CommandText = queryString
                dbCommand.Connection = dbConnection

                Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
                dataAdapter.SelectCommand = dbCommand
                Dim dataSet As System.Data.DataSet = New System.Data.DataSet
                dataAdapter.Fill(dataSet)

                Return dataSet
            End Function


    'This is the function that controls the paging when the next buttons are clicked
    Sub NewPage(sender As Object, e As DataGridPageChangedEventArgs)
        GridMessages.CurrentPageIndex = e.NewPageIndex

        GetMessages()
    End Sub


            'This is the sub event for everytime the edit button is clicked.
            Sub btnEdit_Clicked(Sender as object, e as DataGridCommandEventArgs)



            End Sub

</script>
<html>
<head>
    <link media="screen" href="../StyleSheet.css" type="text/css" rel="stylesheet" />
</head>
<body background="../images/bg.jpg">
    <div align="center">
        <form runat="server">

            <table cellspacing="0" cellpadding="0" width="1003" border="0">
                <tbody>
                    <tr>
                        <td valign="top" background="../images/title.jpg" height="100">

                            <table cellspacing="0" cellpadding="0" width="1003" border="0">
                                <tbody>
                                    <tr>
                                        <td valign="bottom" align="middle" height="88">
                                            Log Out</td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="middle">

                            <br />
                            <asp:DataGrid id="GridMessages" runat="server" BorderColor="White" BorderWidth="1px" AutoGenerateColumns="False" AllowPaging="True" BorderStyle="None" CellPadding="3" PageSize="5" OnPageIndexChanged="NewPage">
                                <HeaderStyle backcolor="Gray"></HeaderStyle>
                                <PagerStyle borderwidth="1px" bordercolor="Black" borderstyle="Solid" backcolor="Gray"></PagerStyle>
                                <Columns>
                                    <asp:TemplateColumn Visible="False" HeaderText="ID">
                                        <ItemStyle width="125px"></ItemStyle>
                                        <ItemTemplate>
                                            <%# Container.DataItem("ID") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Name">
                                        <ItemStyle width="125px"></ItemStyle>
                                        <ItemTemplate>
                                            <%# Container.DataItem("GuestName") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Email">
                                        <ItemStyle width="125px"></ItemStyle>
                                        <ItemTemplate>
                                            <%# Container.DataItem("GuestEmail") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Homepage">
                                        <ItemStyle width="125px"></ItemStyle>
                                        <ItemTemplate>
                                            <%# Container.DataItem("GuestHomepage") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Message">
                                        <ItemStyle width="250px"></ItemStyle>
                                        <ItemTemplate>
                                            <%# Container.DataItem("GuestMessage") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:ButtonColumn Text="Edit" ButtonType="PushButton"></asp:ButtonColumn>
                                </Columns>
                            </asp:DataGrid>
                            <br />
                        </td>
                    </tr>
                </tbody>
            </table>
            <br />
            Copyright 2004 David Jenkins.
        </form>
    </div>
</body>
</html>


cheers for any help.....

David
__________________
David Jenkins
 
Old November 9th, 2004, 08:29 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Anyone know what is going on here, it still doing this!

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
Paging in DataGrid vijay_83 ASP.NET 2.0 Basics 0 September 29th, 2006 02:06 PM
datagrid-paging kvanchi ASP.NET 1.0 and 1.1 Basics 2 December 8th, 2004 04:17 AM
Datagrid Paging collie VB.NET 2002/2003 Basics 17 January 25th, 2004 07:02 AM
Datagrid Paging Error: Invalid CurrentPageIndex va Ron Howerton ADO.NET 0 October 22nd, 2003 08:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.