[英]asp.NET button has an onclick event but the connection between the button and the onclick event is not made
這是 productdetails.aspx 文件中的按鈕代碼:
<asp:Button ID="Button2" runat="server" Text="Add to Wish List"
CssClass="btn btn-success" OnClick="Button2_Click" />
這是 productdetails.aspx.cs 文件中的 onclick 事件
protected void Button2_Click(object sender, EventArgs e)
{
if (temp != 1)
{
try
{
con.Open();
string insertWish = "insert into wishlist (labelP, desP, priceP, QtyP, photoPath) values (@labelP, @desP, @priceP, @QtyP, @photoPath)";
SqlCommand com = new SqlCommand(insertWish, con);
com.Parameters.AddWithValue("@labelP", lblP.Text);
com.Parameters.AddWithValue("@desP", desP.Text);
com.Parameters.AddWithValue("@priceP", priceP.Text);
com.Parameters.AddWithValue("@QtyP", QtyP.Text);
com.Parameters.AddWithValue("@photoPath", Image1.ImageUrl);
com.ExecuteNonQuery();
Label.Text = "Product added to wish list sucessfully";
con.Close();
}
catch (Exception ex)
{
Response.Write("Error: " + ex.ToString());
}
}
}
單擊按鈕時出現以下錯誤:
CS1061:“productdetails_aspx”不包含“Button2_Click”的定義,並且找不到接受“productdetails_aspx”類型的第一個參數的可訪問擴展方法“Button2_Click”(您是否缺少 using 指令或程序集引用?)
注意:文件鏈接到母版頁
注意:我沒有足夠的聲譽在評論框中提出建議。 因此,將建議張貼在答案部分。
aspx designer
器文件中,如果該文件未刷新,則會導致此錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.