2012-07-23 32 views
0

我有一个问题,我Button1的onclick事件上工作,ASP.Net Button1的的onclick不会服务器

它的工作我的本地计算机上的罚款,但是,它让我错误,当我发布到服务器:

>  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.resourcecenter_default_aspx' does not contain a definition for 'Button1_Click' and no extension 
> method 'Button1_Click' accepting a first argument of type 
> 'ASP.resourcecenter_default_aspx' could be found (are you missing a 
> using directive or an assembly reference?) 
>  
>  Source Error: 
>  
>  
>  Line 66:   <tr> 
>  Line 67:   <td class="style1"> 
>  Line 68:   <asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" /> 
>  Line 69: 
>  Line 70:   </td> 

这里是我的代码:

ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

...... 

<tr> 
     <td class="style1"> 
     <asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" /> 

</td> 

C#:

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

     } 

     protected void Button1_Click(object sender, EventArgs e) 
     { 
      string sqlcode = null; 
      string request = TextBox2.Text.ToString(); 
.....} 

任何人都可以帮我弄清楚是怎么回事? 我真的很感谢你的帮助!

+0

您是否使用网站或Web应用程序? – 2012-07-23 14:42:11

+0

尝试检查按钮的** CausesValidation **属性。 – 2012-07-23 14:49:08

+2

CausesValidation值不影响编译 – 2012-07-23 14:57:32

回答

0

您可能尝试将_Default类封装到唯一的名称空间中,或者改变类名称,以防它与站点中的另一个页面发生冲突,并且它的代码隐藏了相同的类名(_Default)。

相关问题