更新:发现问题。 text属性使用aspx文件中的旧值。它不会考虑回发期间的属性更改。现在,如何解决这个问题是另一回事。
原始问题: 我的页面中有一个文本框,我在页面加载时显示一个值,具体取决于请求的记录。
<ASP:TEXTBOX id="txtWarrantyNoValue" runat="server" CssClass="LabelTextBox" ReadOnly="True"></ASP:TEXTBOX>
在页面加载时,基于查询字符串,我设置了text属性,它完美地运行。但是,在回发时,txtWarrantyNoValue.Text
的值为空字符串。我无法弄清楚为什么会发生这种情况。
编辑:
protected void Page_Load( object sender, System.EventArgs e ) {
try {
if ( Request.QueryString[ "MESSAGE" ] != null && Request.QueryString[ "MESSAGE" ] != "" ) objErrorDisplay.MessageCode = Request.QueryString[ "MESSAGE" ];
string strWarrCommData = Request.QueryString[ Constants.QS_DATA_FLAG ];
if ( strWarrCommData != null && strWarrCommData.Trim().Equals( Constants.QS_COMMISSION_DATA ) ) bWarrantyScreen = false;
strScreenMode = Request.QueryString[ Constants.SESSION_MODE ];
if ( strScreenMode == null ) strScreenMode = Constants.SCREEN_MODE_MODIFY;
if ( strScreenMode == "" ) strScreenMode = Constants.SCREEN_MODE_MODIFY;
hdnScreenMode.Value = strScreenMode;
ApplyPermissions();
Localize();
BindDropDowns();
if ( !IsPostBack && strScreenMode != Constants.SCREEN_MODE_NEW ) this.GetWarrantyContractData();
SetControlStyleByScreenMode();
}
catch ( FANUCBaseException fbeEx ) {
objErrorDisplay.ErrorToLog = fbeEx;
}
}
private void BindDropDowns() {
this.ddlSalesType.Attributes.Add( "DataSource", "DefaultDataIslands" );
this.ddlSalesType.Attributes.Add( "DataMember", Constants.DI_SALES_TYPE );
this.ddlSalesType.Attributes.Add( "IsBlankReqd", "Y" );
this.ddlSalesType.Attributes.Add( "SelectedValue", Request.Form[ "ddlSalesType" ] );
this.ddlCurrency.Attributes.Add( "DataSource", "DefaultDataIslands" );
this.ddlCurrency.Attributes.Add( "DataMember", Constants.DI_CURRENCY_CODE );
this.ddlCurrency.Attributes.Add( "IsBlankReqd", "Y" );
this.ddlCurrency.Attributes.Add( "SelectedValue",Request.Form[ "ddlCurrency" ] );
}
Function to get the data
virtual public Row[] GetWarrantyContract( Row objWarrantyFilter, FANUC.Common.BaseClasses.PagingEventArgs e ) {
string strSqlQuery
= " SELECT"
+ " WRNT_Warranty_No,"
+ " WRNT_Seiban,"
+ " WRNT_HQ_Seiban,"
+ " CASE"
+ " WHEN WRNT_Data_Flag = '1' then 'Warranty'"
+ " WHEN WRNT_Data_Flag = '2' then 'Commission'"
+ " ELSE ''"
+ " END AS WRNT_Data_Flag,"
+ " WRNT_Data_Flag as WRNT_Data_Flag_Value,"
+ " WRNT_Unique_Key,"
+ " CASE"
+ " WHEN WRNT_IM_Flag = 'I' then 'Installation'"
+ " WHEN WRNT_IM_Flag = 'M' then 'Maintenance'"
+ " WHEN WRNT_IM_Flag = 'X' then 'Completed'"
+ " ELSE ''"
+ " END AS WRNT_IM_Flag,"
+ " WRNT_IM_Flag as WRNT_IM_Flag_Value,"
+ " WRNT_System_OS_No,"
+ " WRNT_Entry_Seiban_Date,"
+ " WRNT_Warranty_Print_Date,"
+ " WRNT_MTB_Code,"
+ " WRNT_MTB_Name,"
+ " WRNT_Product_ID,"
+ " WRNT_Product_Name,"
+ " WRNT_Product_Serial_No_FA,"
+ " WRNT_Product_Serial_No_ROBO,"
+ " WRNT_Dealer_ID,"
+ " WRNT_Dealer_Name,"
+ " WRNT_End_Cust_ID,"
+ " WRNT_End_Cust_Name,"
+ " WRNT_Total_Amount,"
+ " WRNT_POS_No,"
+ " WRNT_Spec,"
+ " WRNT_Sales_Divide_No,"
+ " WRNT_Sales_Type,"
+ " WRNT_Shipped_Date,"
+ " WRNT_Commission_Fee,"
+ " WRNT_Commission_Rate,"
+ " WRNT_Without_Tax_Fee,"
+ " WRNT_Tax_Fee,"
+ " WRNT_Tax_Rate,"
+ " WRNT_Actual_Destination,"
+ " WRNT_Sales_Group_Code,"
+ " WRNT_Sales_Group_Name,"
+ " WRNT_HQ_To_Country,"
+ " WRNT_HQ_Destination,"
+ " WRNT_Invoiced_Flag,"
+ " WRNT_Invoive_No,"
+ " WRNT_Invoice_Date,"
+ " WRNT_Warranty_Start_Date,"
+ " WRNT_Warranty_End_Date,"
+ " WRNT_Local_Sale_Flag,"
+ " WRNT_Currency_Code,"
+ " WRNT_Seiban_Code,"
+ " WRNT_Comments,"
+ " Use_Count,"
+ " WRNT_Deferred_Revenues_Generated_Flag,"
+ " WRNT_CreatedDate "
+ " FROM"
+ " TBL_Warranty";
Row objFilter = new Row();
objFilter[ "WRNT_Warranty_No~like" ] = objWarrantyFilter[ "WRNT_Warranty_No" ];
objFilter[ "WRNT_Seiban~like" ] = objWarrantyFilter[ "WRNT_Seiban" ];
objFilter[ "WRNT_Entry_Seiban_Date~>=*_From" ] = objWarrantyFilter[ "WRNT_Entry_Seiban_Date_From" ];
objFilter[ "WRNT_Entry_Seiban_Date~<=*_To" ] = objWarrantyFilter[ "WRNT_Entry_Seiban_Date_To" ];
objFilter[ "WRNT_End_Cust_Name~like" ] = objWarrantyFilter[ "WRNT_End_Cust_Name" ];
objFilter[ "WRNT_Warranty_Print_Date~>=*_From" ] = objWarrantyFilter[ "WRNT_Warranty_Print_Date_From" ];
objFilter[ "WRNT_Warranty_Print_Date~<=*_To" ] = objWarrantyFilter[ "WRNT_Warranty_Print_Date_To" ];
objFilter[ "WRNT_Warranty_End_Date~>=*_From" ] = objWarrantyFilter[ "WRNT_Warranty_End_Date_From" ];
objFilter[ "WRNT_Warranty_End_Date~<=*_To" ] = objWarrantyFilter[ "WRNT_Warranty_End_Date_To" ];
objFilter[ "WRNT_MTB_Name~like" ] = objWarrantyFilter[ "WRNT_MTB_Name" ];
objFilter[ "WRNT_Product_ID~like" ] = objWarrantyFilter[ "WRNT_Product_ID" ];
objFilter[ "WRNT_HQ_Destination~like" ] = objWarrantyFilter[ "WRNT_HQ_Destination" ];
objFilter[ "WRNT_Total_Amount" ] = objWarrantyFilter[ "WRNT_Total_Amount" ];
objFilter[ "WRNT_Product_Serial_No_ROBO~like" ] = objWarrantyFilter[ "WRNT_Product_Serial_No_ROBO" ];
objFilter[ "WRNT_Product_Serial_No_FA~like" ] = objWarrantyFilter[ "WRNT_Product_Serial_No_FA" ];
objFilter[ "WRNT_Invoiced_Flag" ] = objWarrantyFilter[ "WRNT_Invoiced_Flag" ];
objFilter[ "WRNT_Local_Sale_Flag" ] = objWarrantyFilter[ "WRNT_Local_Sale_Flag" ];
objFilter[ "WRNT_Data_Flag" ] = objWarrantyFilter[ "WRNT_Data_Flag" ];
objFilter[ "WRNT_HQ_Seiban~like" ] = objWarrantyFilter[ "WRNT_HQ_Seiban" ];
CommonBQ objCommonBQ = new CommonBQ();
string strSearchClause = objCommonBQ.CreateFilter( objFilter );
int iWarrantyFromIndex = strSearchClause.IndexOf( "WRNT_Warranty_End_Date_From" );
int iWarrantyToIndex = strSearchClause.IndexOf( "WRNT_Warranty_End_Date_To" );
if ( iWarrantyFromIndex != -1 && iWarrantyToIndex == -1 ) {
int iWarrantyEndSpaceIndex = strSearchClause.IndexOf( " ", iWarrantyFromIndex );
strSearchClause = strSearchClause.Substring( 0, iWarrantyEndSpaceIndex ) + " OR WRNT_Warranty_End_Date IS NULL " + strSearchClause.Substring( iWarrantyEndSpaceIndex + 1 ) ;
}
string strCountQuery = " SELECT COUNT( 1 ) FROM TBL_Warranty";
string strFinalString = "";
string strConnector = " WHERE ";
if ( !strSearchClause.Equals( "" ) ) {
strFinalString = strSqlQuery + strConnector + strSearchClause ;
strCountQuery += strConnector + strSearchClause ;
}
else {
strSqlQuery += strConnector ;
int iFirstPos = strSqlQuery.IndexOf( "AND", 0 );
string strFirstPart = strSqlQuery.Substring( 0, iFirstPos );
string strSecondPart = strSqlQuery.Substring( iFirstPos + 3, strSqlQuery.Length - iFirstPos - 3 );
strFinalString = strFirstPart + strSecondPart;
}
strFinalString += " ORDER BY CAST( WRNT_Warranty_No AS INT ) DESC ";
return GetRows( strFinalString, strCountQuery, CreateParameterArray( objWarrantyFilter ), CommandType.Text, null, e );
}
答案 0 :(得分:0)
最好使用ViewState[""]
或SessionState[""]
。这对你来说很好。
答案 1 :(得分:0)
在页面加载事件中使用if(!IsPostBack)
if(!IspostBack)
{
//Your code goes here
}
将所有代码写入条件之内就可以了。