Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按钮单击事件在ASP.NET C背后的代码中不起作用#_C#_Asp.net - Fatal编程技术网

C# 按钮单击事件在ASP.NET C背后的代码中不起作用#

C# 按钮单击事件在ASP.NET C背后的代码中不起作用#,c#,asp.net,C#,Asp.net,我的网站上有一个按钮根本不起作用。每次我在代码隐藏中的按钮事件中编写脚本时,都会出现以下错误: Server Error in '/website.com' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the foll

我的网站上有一个按钮根本不起作用。每次我在代码隐藏中的按钮事件中编写脚本时,都会出现以下错误:

 Server Error in '/website.com' 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: 'ASP.test_aspx' does not contain a 
   definition for 'btnSubmit_Click' and no extension method 
   'btnSubmit_Click' accepting a first argument of type 'ASP.test_aspx' 
   could be found (are you missing a using directive or an assembly 
   reference?)

 Source Error:


  Line 5:  
  Line 6:  
  Line 7:  <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
     OnClick="btnSubmit_Click" />
  Line 8:  
  Line 9:  
资料来源:

  <%@ Page Title="" Language="C#" MasterPageFile="~/webMaster.Master"  
  AutoEventWireup="True" CodeBehind="Test.aspx.cs"  
  Inherits="website.Test"  %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" 
     runat="server">
      <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
       OnClick="btnSubmit_Click" CausesValidation="False" />

      <asp:Label ID="lblmsg" runat="server"></asp:Label>  
    </asp:Content>


您没有显示所需代码的第三部分,在该部分中,事件使用委托进行初始化,诸如此类。自动创建的代码,我们通常不太注意。请参阅文件
Formxxx.Designer.cs
中的方法
InitializeComponent()


为了保持简单,我建议:只需删除按钮单击事件处理程序,然后通过在设计器中单击按钮,使用VisualStudio再次创建它。然后正确创建所有必需的代码部分。

只需从后端删除click事件受保护的void btnSubmit\u click(object sender,EventArgs e)
,并从aspx构建解决方案中删除
OnClick=“btnSubmit\u click”
,然后再次定义click事件并绑定它


删除自动生成的单击事件时会发生这种情况。

似乎说明了这一点:
ASP.test\u aspx
vs.
网站
(名称空间)。你是什么意思?请解释您的评论。我已经删除了旧按钮,然后从设计面板双击,创建了与新添加的按钮关联的事件处理程序,并将我的代码粘贴到其中!我还运行了“重建我的解决方案”,删除了旧的test.aspx.designer.cs,并右键单击test.aspx以转换为应用程序以创建新的设计器。所有这些都不适合我!你不必粘贴任何东西。只需在VisualStudio中创建按钮和事件,并在空事件处理程序中设置调试器断点。检查在单击按钮时是否执行事件处理程序。如果这样做有效,那么开始将代码放入事件处理程序中。但如果它不起作用,您必须修复可能已损坏的解决方案和/或项目。我将旧按钮替换为新按钮,新按钮上留下断点(没有代码)。这个按钮在我的开发机器上起作用了。然而,当它部署在托管网站上时,它不起作用,并且它给出了一个编译错误@Max看起来像是部署问题。相同的CPU架构(32/64位)?您是否在托管网站上启用了所有调试选项?开发和托管网站上的不同IIS设置?确切的错误是什么?至少我猜错误消息与上面的原始帖子不同,因为现在应该出现
btnSubmit\u点击
。您是否在VS中发布了
?只是快速更新。我刚刚将codebehind更改为CodeFile,按钮工作了!你可以用两种方法中的任何一种!我试过你说的,一次是手动的,另一次是自动的,但没有成功!
  <%@ Page Title="" Language="C#" MasterPageFile="~/webMaster.Master"  
  AutoEventWireup="True" CodeBehind="Test.aspx.cs"  
  Inherits="website.Test"  %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" 
     runat="server">
      <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
       OnClick="btnSubmit_Click" CausesValidation="False" />

      <asp:Label ID="lblmsg" runat="server"></asp:Label>  
    </asp:Content>
 namespace website {
     public partial class Test {

    /// <summary>
    /// btnSubmit control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind  
        file.
    /// </remarks>
       protected global::System.Web.UI.WebControls.Button btnSubmit;

    /// <summary>
    /// lblmsg control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind 
        file.
    /// </remarks>
    protected global::System.Web.UI.WebControls.Label lblmsg;
   }
 }