大家好,我有一个奇怪的问题,希望你能帮助我,我有一个普通的 Asp.net 页面,我在其中处理页面加载中的一些状态数据,如下所示
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["TempD"] = null;
Session["Totals"] = null;
//Handling Sessions here...
}
}
问题是在一个按钮回发页面加载被调用两次 IsPostBack = true 没关系,第二次但是 IsPostBack = false !!!这导致我的代码进入 if 条件并重置状态信息,这是不正确的,我在页面中使用了一些 Ajax Toolkit 控件,没有更新面板,只有一些日历和自动完成。这是导致回发的按钮的代码
protected void TSBtnAddItem_Click(object sender, EventArgs e)
{
if (Session["TempD"] != null)
{
DataLayer.Invoicing.CInvoiceDetail InvoDetails = (DataLayer.Invoicing.CInvoiceDetail)Session["TempD"];
DataLayer.Invoicing.CVarInvoiceDetail var = new DataLayer.Invoicing.CVarInvoiceDetail();
if (LblCurrencyValue.Visible)
{
var.CurencyID = int.Parse(LblCurrencyValue.ToolTip);
}
else
{
var.CurencyID = int.Parse(CboCurrencyValue.SelectedValue);
}
var.ID = 0;
var.InvoiceHeaderID = Convert.ToInt64(InvoiceHeaderID.Value);
var.IsChanges = true;
var.IsFreightItem = false;
var.IsOption = true;
var.ItemAmount = decimal.Parse(txtItemVal.Text);
var.ItemName = CboItemName.SelectedItem.Text;
var.ItemID = int.Parse(CboItemName.SelectedValue);
var.Remarks = "";
if (IsPartLoad.Checked == true)
{
ShipLink.Publics.ApplicationMethods.Item32 itm = LstCalcType.Find(delegate(ShipLink.Publics.ApplicationMethods.Item32 p1) { return Convert.ToInt32(p1.Name.Trim()) == var.ItemID; });
if (itm == null)
{
ADDToCalcList(Convert.ToString(var.ItemID));
if (NumUpDownPortRatio.Enabled == false)
var.ItemAmount = ChangeAmount(var.ItemID, var.ItemAmount);
}
}
InvoDetails.lstCVarInvoiceDetail.Add(var);
Session["TempD"] = InvoDetails;
UGrdInvoiceDetailGrid.DataSource = InvoDetails.lstCVarInvoiceDetail;
UGrdInvoiceDetailGrid.DataBind();
CalcSalesTax();
CalcDiscount();
AddCaseUGrdInvoiceTotalGrid();
}
}