if(!Page.IsPostBack) 的含义

本文介绍了.NET中Page.IsPostBack属性的应用,通过示例代码展示了如何判断页面是否为初次加载,以便于设置初始状态或将控件恢复到默认值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

。net学习笔记

! Page IsPostback   如果是第一次返回值,执行下面的语句(如 This.TextBox1.Text="";  返回TextBox1的值为空),如果不是第一次,返回值按输入的值显示。 

第一个例子:  
private void Page_Load(object sender, System.EventArgs e)
  {
   if(!Page.IsPostBack)
   {
    this.UserName.Text="";
   }
   // 在此处放置用户代码以初始化页面
  }

让第一个控件TextBox文本为空

 
根据代码帮忙了解,GCCode是怎么获取到的 using System; using System.Collections.Generic; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Ymycc.ComUtility; using Ymycc.Wis.Model; using Ymycc.Wis.Com; using Ymycc.Wis.Bll; using Ymycc.Wis.Biz.Bll; using Ymycc.Wis.Biz.Model; using System.Threading; using System.EnterpriseServices; public partial class Bk_Rep_TopACList : WisPage { BlUser blUsr = new BlUser(); BlBizInfo blInfo = new BlBizInfo(); ExpBkOpr expBkOpr = new ExpBkOpr(); protected void Page_Load(object sender, EventArgs e) { lb_Notes.Text = ""; bool runRep = true; DataTable dataTB = null; UserInfo lUser = UserOpr.LogonUser; BlDataMap dco = new BlDataMap(); //tb_VoyageCode.Text = "AW3236E"; tb_VpEtdFrom.Attributes.Add("onclick", "SelectDate(this,'yyyy-MM-dd',0,0)"); tb_VpEtdTo.Attributes.Add("onclick", "SelectDate(this,'yyyy-MM-dd',0,0)"); string bkOfsIn = tb_bkOfsIn.UpcText?.Trim(); string tradeCode = tb_Trade.Text.Trim().ToUpper(); string wk = tb_wk.Text.Trim(); string cmsCode = tb_CustCode.Text.Trim(); string cmsCodeOn = tb_CustCodeOn.Text.Trim(); string GcCode = tb_GCCode.Text.Trim();//GCCode string voyageCodes = tb_VoyageCode.Text.Trim(); string allocVoyCodes = tb_AllocVoy.Text.Trim(); string loadPortCode = tb_LoadPort.Text.Trim(); string dischPortCode = tb_DischPort.Text.Trim(); string finalLocCode = tb_FinalLoc.Text.Trim(); string vpEtdFrom = tb_VpEtdFrom.Text.Trim(); string vpEtdTo = tb_VpEtdTo.Text.Trim(); string caseIDs = tb_CaseIDs.Text.Trim(); string ctrTypes = tb_CtrTypes.Text.Trim(); string pc = ddl_Freight.SelectedValue.Trim(); string ft = "<b>TOP A/C LIST</b>"; ft += bkOfsIn == "" ? "" : (", <b>Bk Office:</b> " + bkOfsIn); ft += voyageCodes == "" ? "" : (", <b>Voyage:</b> " + voyageCodes.ToUpper()); ft += allocVoyCodes == "" ? "" : (", <b>Alloc Voyage:</b> " + allocVoyCodes.ToUpper()); ft += tradeCode == "" ? "" : (", <b>Trade:</b> " + tradeCode.ToUpper()); ft += loadPortCode == "" ? "" : (", <b>LoadPort:</b> " + loadPortCode.ToUpper()); ft += dischPortCode == "" ? "" : (", <b>DischPort:</b> " + dischPortCode.ToUpper()); ft += finalLocCode == "" ? "" : (", <b>FinalLoc:</b> " + finalLocCode.ToUpper()); ft += cmsCode == "" ? "" : (", <b>CustCode:</b> " + cmsCode.ToUpper()); ft += cmsCodeOn == "" ? "" : (", <b>OnCustCode:</b> " + cmsCodeOn.ToUpper()); ft += GcCode == "" ? "" : (", <b>GC Code:</b> " + GcCode.ToUpper());//GCCode ft += vpEtdFrom == "" ? "" : (", <b>ETD From:</b> " + vpEtdFrom); ft += vpEtdTo == "" ? "" : (", <b>To</b> " + vpEtdTo); ft += caseIDs == "" ? "" : (", <b>CaseID:</b> " + caseIDs.ToUpper()); ft += ctrTypes == "" ? "" : (", <b>CtrType:</b> " + ctrTypes.ToUpper()); ft += pc == "" ? "" : (", <b>P/C:</b> " + pc.ToUpper()); List<string> voyages = new List<string>(); if (!Page.IsPostBack) { tb_bkOfsIn.UpcText = lUser.UserOffice?.OfficeCode; //tb_bkOfs.Text = lUser.UserOffice?.OfficeCode; //userOpr.BindUserBizAcsOfsToDDL(ddl_bkOfs, lUser.UserOffice.OfficeCode, false, true, ""); string upfs = blUsr.GetUserPreference(lUser.UserKey, "BK_REP_TOPACLIST"); foreach (ListItem li in this.cbl_ShowFields.Items) { if (upfs.IndexOf(li.Value) >= 0) { li.Selected = true; } } } else { try { if (voyageCodes == "") { if (vpEtdFrom == "" || vpEtdTo == "") { if (wk == "" || tradeCode == "") { throw new Exception("ETD时间范围或者周期,两者必须输入其一!"); } } } if (wk != "" & tradeCode != "") { if (tradeCode == "NCP") { voyageCodes = dco.GetMatched("EXP_BK_EU_WEEKVOY", lUser.UserOffice.OfficeCode, new DataMapParam(DmmField.C0, wk)) + "," + voyageCodes; } if (tradeCode == "MED") { voyageCodes = dco.GetMatched("EXP_BK_MED_WEEKVOY", lUser.UserOffice.OfficeCode, new DataMapParam(DmmField.C0, wk)) + "," + voyageCodes; } } if (vpEtdFrom != "" || vpEtdTo != "") DateTimeHelper.CheckFromToDateTime(ref vpEtdFrom, ref vpEtdTo, "MM", 3); if (voyageCodes != "") { voyageCodes = voyageCodes.Replace(",", ",").Replace(";", ",").Replace(";", ",").TrimEnd(','); foreach (string s in voyageCodes.Split(',')) { voyages.Add(s.Trim()); } } else { string PortList = blInfo.GetOfsVPorts(lUser.UserOffice.OfficeCode); if (string.IsNullOrEmpty(PortList) && !string.IsNullOrEmpty(bkOfsIn))//订舱地不为空且PortList为空 { PortList = blInfo.GetLocByAolOffice(bkOfsIn); } else if (string.IsNullOrEmpty(PortList)) { PortList = string.Empty; } voyages = blInfo.GetVoyagesByvpPorts(PortList, vpEtdFrom, vpEtdTo + " 23:59:59"); } string f = "1=1 "; //if (!string.IsNullOrEmpty(bkOfs)) { // f += " and BkOffice = '" + bkOfs + "'"; //} if (!string.IsNullOrEmpty(loadPortCode)) { f += " and LoadPortCode in ('" + loadPortCode.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(dischPortCode)) { f += " and DischPortCode in ('" + dischPortCode.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(finalLocCode)) { f += " and FinalLocCode in ('" + finalLocCode.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(tradeCode)) { f += " and TradeCode in ('" + tradeCode.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(caseIDs)) { f += " and CaseID in ('" + caseIDs.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(cmsCode)) { f += " and CustCode in ('" + cmsCode.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(cmsCodeOn)) { f += " and OnCustCode in ('" + cmsCodeOn.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(GcCode)) { f += " and GCCode in ('" + GcCode.Replace(",", ",").Replace(",", "','") + "')";//GCCode } if (!string.IsNullOrEmpty(pc)) { f += " and FreightMode in ('" + pc.Replace(",", ",").Replace(",", "','") + "')"; } if (!string.IsNullOrEmpty(allocVoyCodes)) { f += " and AllocVoyage in ('" + allocVoyCodes.Replace(",", ",").Replace(",", "','") + "')"; } string cf = ""; string[] qcArray = null; ctrTypes = ctrTypes.ToUpper().Replace(",", ",").Replace(";", ",").Replace(";", ","); if (ctrTypes != "") { qcArray = ctrTypes.Split(','); foreach (string c in qcArray) { cf += cf == "" ? ("CtrType='" + c + "'") : (" or CtrType='" + c + "'"); } } if (cf != "") f += " and (" + cf + ")"; CargoFields[] qFields = new CargoFields[] { CargoFields.BkOffice, CargoFields.CustCode, CargoFields.CustName, CargoFields.OnCustCode, CargoFields.OnCustName, CargoFields.TradeCode,CargoFields.LoadVoyage, CargoFields.CaseID, CargoFields.CaseIDHolder,CargoFields.GCCode, CargoFields.LoadPortCode, CargoFields.DischPortCode, CargoFields.FinalLocCode, CargoFields.PreCarriageVoyage, CargoFields.AllocVoyage, CargoFields.CtrKey, CargoFields.CtrType, CargoFields.CtrTeu, CargoFields.CtrSize, CargoFields.EirPrinted, CargoFields.FreightMode }; foreach (string v in voyages) { CargoQueryParam cqp = new CargoQueryParam(); cqp.LoadVoyage = v; cqp.BkStatus = "P"; //cqp.CustCode = cmsCode; //cqp.OnCustCode = cmsCodeOn; cqp.BkOfficeIn = bkOfsIn == "" ? lUser.UserOffice?.OfficeCode : bkOfsIn; DataTable d = expBkOpr.PRSelect(cqp, qFields); if (d != null && d.Rows.Count > 0) { if (dataTB == null) { dataTB = d.Clone(); } foreach (DataRow dr in d.Select(f)) { dataTB.Rows.Add(dr.ItemArray); } } Thread.Sleep(20); } } catch (Exception ex) { runRep = false; WriteTxtLog.WriteLog_ExceptionNotes("Bk_ReportGen_TopAccountList: err:" + ex.ToString()); lb_Notes.Text = "<font color='red'>出现错误:</font>" + ex.Message; } //rep control: Dictionary<string, string> udfFieldsTitle = new Dictionary<string, string>(); udfFieldsTitle.Add("BkOffice", "OFFICE"); udfFieldsTitle.Add("PRECARRIAGEVOYAGE", "PRECARRIAGE"); udfFieldsTitle.Add("LOADPORTCODE", "LOADPORT"); udfFieldsTitle.Add("DISCHPORTCODE", "DISCHPORT"); udfFieldsTitle.Add("FINALLOCCODE", "FINALLOC"); List<string> topFields = new List<string>(); topFields.Add(CargoFields.LoadVoyage.ToString()); //topFields.Add(CargoFields.LoadPortCode.ToString()); //topFields.Add(CargoFields.DischPortCode.ToString()); List<string> leftFields = new List<string>(); leftFields.Add(CargoFields.CustCode.ToString()); leftFields.Add(CargoFields.CustName.ToString()); bool showEIR = false; string upfs = ""; //根据栏位选择 foreach (ListItem li in this.cbl_ShowFields.Items) { if (li.Selected) { switch (li.Value.ToString().Trim()) { case "BkOfs": leftFields.Insert(0, CargoFields.BkOffice.ToString()); break; case "OnCust": { leftFields.Add(CargoFields.OnCustCode.ToString()); leftFields.Add(CargoFields.OnCustName.ToString()); }; break; case "CaseID": leftFields.Add(CargoFields.CaseID.ToString()); break; case "CaseIDHdr": leftFields.Add(CargoFields.CaseIDHolder.ToString()); break; case "GCCode": leftFields.Add(CargoFields.GCCode.ToString()); break;//GCCode case "PreCarriage": leftFields.Add(CargoFields.PreCarriageVoyage.ToString()); break; case "AllocVoy": leftFields.Add(CargoFields.AllocVoyage.ToString()); break; case "LoadPort": leftFields.Add(CargoFields.LoadPortCode.ToString()); break; case "DischPort": leftFields.Add(CargoFields.DischPortCode.ToString()); break; case "FinalLoc": leftFields.Add(CargoFields.FinalLocCode.ToString()); break; case "EIR": showEIR = true; break; default: break; } upfs += (upfs == "" ? "" : ",") + li.Value?.Trim(); } } blUsr.SetUserPreference(lUser.UserKey, "BK_REP_TOPACLIST", upfs); string topSort = CargoFields.CustCode.ToString(); string lefSort = ""; List<string> topTTLFields = new List<string>(); List<string> leftTTLFields = new List<string>(); //leftTTLFields.Add("LoadVoyage"); //leftTTLFields.Add("BkOffice"); Dictionary<string, List<string>> udfTopFldVals = new Dictionary<string, List<string>>(); //udfTopFldVals.Add("dischportcode", new string[] { "MYPKE", "IRBAB", "IQUQR", "AEJEA" }); Dictionary<string, List<string>> udfLeftFldVals = new Dictionary<string, List<string>>(); //udfLeftFldVals.Add("BkOffice", new string[] { "SHA", "NGB", "XMN", "DLC" }); Dictionary<string, Dictionary<string, string>> spcFld = new Dictionary<string, Dictionary<string, string>>(); Dictionary<string, string> c20 = new Dictionary<string, string>(); c20.Add("C", "count(CtrKey)"); c20.Add("F", "CtrSize = '20'"); spcFld.Add("20'", c20); Dictionary<string, string> c40 = new Dictionary<string, string>(); c40.Add("C", "count(CtrKey)"); c40.Add("F", "CtrSize = '40' and CtrType <> '40HQ'"); spcFld.Add("40'", c40); Dictionary<string, string> c40HQ = new Dictionary<string, string>(); c40HQ.Add("C", "count(CtrKey)"); c40HQ.Add("F", "CtrType = '40HQ'"); spcFld.Add("40HQ", c40HQ); Dictionary<string, string> c45 = new Dictionary<string, string>(); c45.Add("C", "count(CtrKey)"); c45.Add("F", "CtrSize = '45'"); spcFld.Add("45'", c45); if (showEIR) { Dictionary<string, string> c20_EIR = new Dictionary<string, string>(); c20_EIR.Add("C", "count(CtrKey)"); c20_EIR.Add("F", "CtrSize = '20' and EirPrinted>0"); spcFld.Add("20' EIR", c20_EIR); Dictionary<string, string> c40_EIR = new Dictionary<string, string>(); c40_EIR.Add("C", "count(CtrKey)"); c40_EIR.Add("F", "CtrSize = '40' and CtrType <> '40HQ' and EirPrinted>0"); spcFld.Add("40' EIR", c40_EIR); Dictionary<string, string> c40HQ_EIR = new Dictionary<string, string>(); c40HQ_EIR.Add("C", "count(CtrKey)"); c40HQ_EIR.Add("F", "CtrType = '40HQ' and EirPrinted>0"); spcFld.Add("40HQ EIR", c40HQ_EIR); Dictionary<string, string> c45_EIR = new Dictionary<string, string>(); c45_EIR.Add("C", "count(CtrKey)"); c45_EIR.Add("F", "CtrSize = '45' and EirPrinted>0"); spcFld.Add("45' EIR", c45_EIR); Dictionary<string, string> cTTL = new Dictionary<string, string>(); cTTL.Add("C", "sum(CtrTeu)"); cTTL.Add("F", ""); spcFld.Add("TTL(Teu)", cTTL); Dictionary<string, string> cTTL_EIR = new Dictionary<string, string>(); cTTL_EIR.Add("C", "sum(CtrTeu)"); cTTL_EIR.Add("F", "EirPrinted>0"); spcFld.Add("TTL(Teu) EIR", cTTL_EIR); } uc_ReportGen.ReportRun = runRep; uc_ReportGen.ReportTitle = ft; uc_ReportGen.ReportGenFileName = "Top Account List.xls"; uc_ReportGen.RepGen.InputDataSource = dataTB; uc_ReportGen.RepGen.UdfFieldsTitle = udfFieldsTitle; uc_ReportGen.RepGen.TopFields = topFields; //uc_ReportGen.SpcFieldsReplaceTTL = true; uc_ReportGen.RepGen.LeftFields = leftFields; uc_ReportGen.RepGen.TopTTLFields = topTTLFields; uc_ReportGen.RepGen.TopSort = topSort; uc_ReportGen.RepGen.LeftSort = lefSort; uc_ReportGen.RepGen.SpcTopLastRowFields = spcFld; uc_ReportGen.RepGen.ShowFieldsTitle = true; uc_ReportGen.RepGen.ShowComputeZero = true; uc_ReportGen.RepGen.ShowRightTTL = true; uc_ReportGen.RepGen.ShowBottomTTL = true; uc_ReportGen.RepGen.ComputeExpress = "sum(CtrTeu)"; //统计的方式:除spc外,所有数据都用此统计方式 uc_ReportGen.RepGen.ShowRowNo = false; //uc_ReportGen.ShowZero = false; uc_ReportGen.RepGen.FieldTTLName = "TTL"; uc_ReportGen.RepGen.TopTTLName = "TTL(Teu)"; uc_ReportGen.RepGen.LeftTTLName = "TTL"; uc_ReportGen.RepGen.SpcSortColumn = "L:Desc"; } } }
最新发布
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值