2012-07-23 24 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)。

相關問題