2010-09-06 54 views
0

給出的形式:按鈕的onclick錯誤

<form runat="server"> 
    **Omitted field data for simplicity**   
    <asp:Button runat="server" id="btn_addNewPrice" OnClick="newPrice_click" Text="Add New Price" />  
</form> 

而後面的代碼:

// A new price has been entered 
void newPrice_click(object sender, EventArgs e) 
{ 
    // Get form values 
    DateTime frm_datestart = DateTime.Parse(dateStart.Text); 
    DateTime frm_dateend = DateTime.Parse(dateEnd.Text); 
    double frm_percent = double.Parse(percentage.Text); 
} 

我得到的錯誤:

CS1061: 'ASP.admin_editproduct_aspx' does not contain a definition for 'newPrice_click' and no extension method 'newPrice_click' accepting a first argument of type 'ASP.admin_editproduct_aspx' could be found (are you missing a using directive or an assembly reference?)

+1

您是否在newPrice_Click代碼中放置了斷點以查看它是否已到達? – 2010-09-06 10:00:12

+0

我總是這樣做,我選擇按鈕,轉到屬性,然後在事件選項卡(照明符號)上選擇要用於點擊的事件,或者雙擊以創建一個新的。 – Ivo 2010-09-06 10:09:08

+0

感謝ivo,它生成了看起來完美運行的shell代碼。 – 2010-09-06 10:16:30

回答

2

如果你把一個斷點在你的代碼,你可以看到代碼是否被擊中(斷點被擊中)。

我認爲你應該使用一個asp:按鈕或使用以下tuterial實現回傳: http://www.dotnetspider.com/resources/1521-How-call-Postback-from-Javascript.aspx

編輯: 我總是這樣,我選擇按鈕,進入屬性,然後在事件選項卡上(照明符號)我選擇要用於點擊的事件,或者雙擊創建一個新事件。

1

用途:

protected void newPrice_click(object sender, EventArgs e) 
{ 

} 
0

因爲你沒有指定訪問修飾符,您newPrice_click法默認爲私有。嘗試將其聲明爲受保護並查看是否有幫助。

頁面類實際創建的方式是從.cspx文件中的類繼承的.aspx文件創建一個類。如果事件處理函數方法是私有的,那麼它不能從子類中看到,也就是說.aspx文件中的類。