我必须将应用程序从 Windows 窗体移植到 ASP.net
在我尝试使用其他表单将销售数据添加到表单之前,一切正常。在 Windows 窗体中它工作正常,但是当我在 ASP 中尝试它时,我得到“用户代码未处理空引用异常”
当我尝试从主表单访问“添加新销售”时,会弹出此消息。
我的“添加销售表格”中的代码是:
public partial class AddSaleForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public Sale GetData()
{
return new Sale(IdTextbox.Text, DateTextbox.Text, LocationTextBox.Text, Convert.ToDouble(PitchCostTextbox.Text), Convert.ToInt32(NumPitchesTextbox.Text), CharityCheckbox.Checked, CharityNameTextbox.Text, CateringCheckBox.Checked);
}
知道出了什么问题,我在哪里可以解决它?
这是构造函数:
namespace AntiqueSale
{
[Serializable]
public class Sale : IComparable<Sale>
{
private String saleId;
public String SaleId
{
get { return saleId; }
set { saleId = value; }
}
private String saleDate;
private String location;
private double pitchCost;
private int numPitches;
private bool charity;
public bool Charity
{
get { return charity; }
set { charity = value; }
}
private String charityName;
private bool catering;
public Sale(String saleId,
String saleDate,
String location,
double pitchCost,
int numPitches,
bool charity,
String charityName,
bool catering)
{
this.saleId = saleId;
this.saleDate = saleDate;
this.location = location;
this.pitchCost = pitchCost;
this.numPitches = numPitches;
this.charity = charity;
this.charityName = charityName;
this.catering = catering;
}
public override string ToString()
{
String str;
String charityString;
String cateringString;
String charityNameString;
if (charity)
{
charityString = "Yes";
charityNameString = charityName;
}
else
{
charityString = "No";
charityNameString = "N/A";
}
if (catering)
{
cateringString = "Yes";
}
else
{
cateringString = "No";
}
str = String.Format("{0}: {1}: {2}: {3}: {4}: {5}: {6}: {7}",
saleId,
saleDate,
location,
pitchCost,
numPitches,
charityString,
charityNameString,
cateringString);
return str;
}
public int CompareTo(Sale sale)
{
return this.SaleId.CompareTo(sale.SaleId);
}
}
构造函数不是我设计的,这是我收到的需要修改成asp的起始代码。