Reputation: 785
My asp.net Web Form page keeps on crashing when I add (OnPageIndexChanging="OnPageIndexChanging" PageSize="10") to my gridview. The grid view is as follows:
<asp:GridView ID="netEventGridView" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="10">
But when the page loads I get the error:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'startpage_aspx' does not contain a definition for 'OnPageIndexChanging' and no extension method 'OnPageIndexChanging' accepting a first argument of type 'startpage_aspx' could be found (are you missing a using directive or an assembly reference?)
The error does not appear if I remove OnPageIndexChanging and PageSize. The code in the codeBehind file is as follows:
protected void OnPagingIndexChanging(object sender, GridViewPageEventArgs e)
{
netEventGridView.PageIndex = e.NewPageIndex;
this.BindGrid();
}
The error also occurred when I would click the following button identified by this html code:
<asp:Button Text="Create New NetEvent" runat="server" ID="testBtn" OnClick="testBtn_Click"/>
I get this error when clicking the button:
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.
In both cases I set breakpoints in my codeBehind file and it was never reached. It seems like there is a problem when any method in the codebehind file is called and I am not sure why.
Upvotes: 1
Views: 344
Reputation: 8246
I see the event handler name is different in your aspx and code behind. Can you change it and try again? Change it to :
<asp:GridView ID="netEventGridView" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="OnPagingIndexChanging" PageSize="10">
Upvotes: 1