[英]How to call function from class file (.cs) file to another code behind file (.aspx.cs)?
[英]How to call a method in .cs file in App_Code folder in aspx.cs file?
App_Code 文件夾中的 My.cs 文件
namespace OnlineShoppingSite.App_Code
{
public class Product
{
public Product(string prodID, string prodName, string prodDesc,
decimal unitPrice, string prodImage, string prodImage2, string prodDetails, string prodMeasurement, string prodCare)
public Product getProduct(string prodID)
{
}
}
我的.aspx.cs 文件
using OnlineShoppingSite.App_Code;
namespace OnlineShoppingSite
{
public partial class ProductDetails : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
如何檢索 .aspx.cs 文件中的 getProduct 方法? 我添加了使用“OnlineShoppingSite.App_Code;” 在文件頂部,但它向我顯示此錯誤 'App_Code' 在您的命名空間 'OnlineShoppingSite' 中不存在(您是否缺少在線程序集參考?)“
您的第一個構造函數缺少大括號。
public Product(string prodID, string prodName, string prodDesc,
decimal unitPrice, string prodImage, string prodImage2, string prodDetails,
string prodMeasurement, string prodCare)
{
}
您可以做的是從命名空間名稱中刪除.App_Code
,然后從代碼隱藏頁面中刪除命名空間塊。
namespace OnlineShoppingSite
{
public class Product
{
public Product(string prodID, string prodName, string prodDesc, ...)
{
}
public Product getProduct(string prodID)
{
}
}
}
.aspx.cs 文件
using OnlineShoppingSite;
public partial class ProductDetails : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.