2017-10-11 44 views
1

当我向GridView添加(OnPageIndexChanging =“OnPageIndexChanging”PageSize =“10”)时,我的asp.net Web窗体页面不断崩溃。网格视图如下:ASP.NET编译错误(无法调用CodeBehind文件中的方法)

<asp:GridView ID="netEventGridView" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="10">

但是在页面加载时出现错误:

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?)

的错误不会出现,如果我删除OnPageIndexChanging和每页。在代码隐藏文件中的代码如下:

protected void OnPagingIndexChanging(object sender, GridViewPageEventArgs e) 
    { 
     netEventGridView.PageIndex = e.NewPageIndex; 
     this.BindGrid(); 
    } 

错误也发生时,我会点击这个HTML代码确定了以下按钮:

<asp:Button Text="Create New NetEvent" runat="server" ID="testBtn" OnClick="testBtn_Click"/> 

点击该按钮时,我得到这个错误:

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.

在这两种情况下,我在我的codeBehind文件中设置断点,它从来没有达到过。好像有一个问题,当代码隐藏文件中的任何方法被调用,我不知道为什么。

回答

1

我看到事件处理程序的名称不同于你的aspx和后面的代码。你可以改变它,然后再试一次吗? 更改为:

<asp:GridView ID="netEventGridView" runat="server" AutoGenerateColumns="false" AllowPaging="true" 
OnPageIndexChanging="OnPagingIndexChanging" PageSize="10"> 
+0

修复它非常感谢!有趣的我没有明白。 – FrankTheTank

+0

我现在单击此按钮时也会出现此错误:{/'应用程序中的服务器错误。 验证视图状态MAC失败。如果此应用程序由Web场或群集托管,请确保配置指定相同的验证密钥和验证算法。 AutoGenerate不能在群集中使用。 请参阅http://go.microsoft.com/fwlink/?LinkID=314055获取更多信息。} – FrankTheTank

+0

您应该在不同的问题中发布该问题并将其标记为答案。 – Coding

相关问题