【问题标题】:No definition for 'DisplayBox_TextChanged' [closed]'DisplayBox_TextChanged'没有定义[关闭]
【发布时间】:2011-07-24 01:51:18
【问题描述】:
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: 'ASP.calculator_aspx' does not contain a definition for 'DisplayBox_TextChanged' and no extension method 'DisplayBox_TextChanged' accepting a first argument of type 'ASP.calculator_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:enter code here

Line 18:     <tr>
Line 19:         <td colspan="5">
Line 20:             <asp:TextBox ID="DisplayBox" runat="server" 
Line 21:                 ontextchanged="DisplayBox_TextChanged" Width="268px"></asp:TextBox>
Line 22:         </td>
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class calculator : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

【问题讨论】:

  • 请提供导致此错误的代码的最小完整示例。
  • 对我来说,编译器说我没有方法。我确实有这个方法,但是里面有一些错误。我在编译时忽略了这些错误,它给了我同样的错误消息。我只是评论了那些错误行并再次编译。它奏效了。

标签: c# error-handling


【解决方案1】:

如果要支持 DisplayBox 的 TextChanged 事件,请在 .cs 文件中实现 DisplayBox_TextChanged 事件。

protected void DisplayBox_TextChanged(object sender, EventArgs e)
{
    //logic...
}

如果您对 TextChanged 事件不感兴趣,请从 XAML 文件中删除以下部分(第 21 行)。

ontextchanged="DisplayBox_TextChanged"

【讨论】:

    【解决方案2】:

    听起来,从您提供的一小段代码来看,您正在尝试响应ontextchanged 事件,但您没有实现DisplayBox_TextChanged 方法来处理该事件。从上面的代码中删除ontextchanged="DisplayBox_TextChanged,或者创建一个名为DisplayBox_TextChanged的方法

    【讨论】:

      【解决方案3】:

      在您的代码隐藏文件中,您需要实现 DisplayBox_TextChanged 方法。

      看起来像这样

      protected void DisplayBox_TextChanged( EventArgs e )
      {
          //code here
      }
      

      方法的 MSDN http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.ontextchanged(v=VS.90).aspx

      【讨论】:

      • 不应该是protected void DisplayBox_TextChanged(object sender, EventArgs e)吗?
      【解决方案4】:

      试试这个:

      在项目资源管理器中右键单击项目并选择添加引用并添加 dll 文件 StructureMap.dll,它可能位于项目的 bin 目录中

      http://forums.asp.net/t/1381741.aspx/1

      JMax

      【讨论】:

      • 嗯...这个答案完全没有意义,甚至似乎与问题/错误无关。
      • 我的回答几乎和其他人一样,但是在对这个问题进行一些研究时,它看起来更像是一个 MVC 问题(尽管原始海报没有详细说明)。它看起来更像 MVC,因为他们的评论是:“并且找不到接受类型为 'ASP.calculator_aspx' 的第一个参数的扩展方法 'DisplayBox_TextChanged'(您是否缺少 using 指令或程序集引用?)”。我对此进行了一些研究,这就是我提交链接的原因。
      猜你喜欢
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2016-09-19
      • 2016-01-20
      • 2021-11-06
      • 2021-03-07
      相关资源
      最近更新 更多