简体   繁体   English

ASP.NET 编译错误(无法调用 CodeBehind 文件中的方法)

[英]ASP.NET Compilation Error (Can't Call Methods in CodeBehind File)

My asp.net Web Form page keeps on crashing when I add (OnPageIndexChanging="OnPageIndexChanging" PageSize="10") to my gridview.当我将 (OnPageIndexChanging="OnPageIndexChanging" PageSize="10") 添加到我的 gridview 时,我的 asp.net Web 窗体页面不断崩溃。 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?)编译器错误消息:CS1061:“startpage_aspx”不包含“OnPageIndexChanging”的定义,并且找不到接受“startpage_aspx”类型的第一个参数的扩展方法“OnPageIndexChanging”(您是否缺少 using 指令或程序集引用?)

The error does not appear if I remove OnPageIndexChanging and PageSize.如果删除 OnPageIndexChanging 和 PageSize,则不会出现该错误。 The code in the codeBehind file is as follows: codeBehind文件中的代码如下:

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:当我单击此 html 代码标识的以下按钮时,也会发生错误:

<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.验证视图状态 MAC 失败。 If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm.如果此应用程序由 Web Farm 或集群托管,请确保配置指定相同的 validationKey 和验证算法。 AutoGenerate cannot be used in a cluster. AutoGenerate 不能在集群中使用。

See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=314055

In both cases I set breakpoints in my codeBehind file and it was never reached.在这两种情况下,我都在我的 codeBehind 文件中设置了断点,但从未达到过。 It seems like there is a problem when any method in the codebehind file is called and I am not sure why.调用代码隐藏文件中的任何方法时似乎存在问题,但我不知道为什么。

I see the event handler name is different in your aspx and code behind.我看到您的 aspx 和后面的代码中的事件处理程序名称不同。 Can you change it and try again?你能改变它并再试一次吗? Change it to :将其更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM