postBack之后的值不正确 [英] Incorrect Values after postBack

查看:62
本文介绍了postBack之后的值不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控件内使用控件.第一次加载两个控件时,一切正常.
但是,当发生回发时,用于显示第二个控件的值将显示不正确的值.

第一控件的属性

I am using control within control. When first time both control are loaded then everything goes fine.
But When post Back is occur then, Values that are used to display second control shows shows incorrect values.

Properties of First Control

public COAGroup GroupName
   {

       get
       {
           if (hdnCOAGroup.Value == "")
               return COAGroup.F;
           else
               return (COAGroup)Enum.Parse(typeof(COAGroup), hdnCOAGroup.Value, true);
          
       }
       set
       {
           _GroupName = value;
           hdnCOAGroup.Value = value.ToString();
           setButtonScript();
       }
}



GroupName属性的值将在注册Java脚本代码中使用,该代码将在新窗口中打开另一个用户控件.
将在第一个用户控件的页面加载事件中调用将注册此代码的函数.



The Values of GroupName property will be used in register Java Script Code that will open another User Control in new window.
The function that will register this code is called in page load event of first User Control.

private void setButtonScript()
    {
        string strTextFieldName = this.txtName.ClientID;
        string strValueFieldName = this.txtHdnCode.ClientID;
        string strTitleFieldName = this.lblAccountName.ClientID;
        String AppRoot = ConfigurationManager.AppSettings["ApplicationRoot"].ToString();
        this.btnLookup.Attributes.Add("onclick", "Show_Popup(0,0,'COA_Lookup2','" + AppRoot + "CommonComponents/COASelection.aspx?qsTextFieldName=" + strTextFieldName + "&qsValueFieldName=" + strValueFieldName + "&qsPostBackFieldName=" + _PostBackControlName + "&qsPostBackEvent=" + _PostBackControlEvent + "&qsSwitchTextField=" + SwitchTextField.ToString() + "&qsTitleFieldName=" + strTitleFieldName + "&qsGroupName=" + GroupName.ToString() + "&qsAccountTypes=" + AccountTypes + "&qsAccountLevels=" + AccountLevels + "&qsWithTitle=1 &qsExcludeAccount=" + ExcludeAccounts + "&qsShowAllAccounts=" + ShowAllAccounts + "' ); return false;");


并且我们将此方法称为


and We Call this method as

protected void Page_Load(object sender, EventArgs e)
    {
        setButtonScript();
        
    }


我们在运行时设置了ModuleName属性,但是在打开弹出窗口时它会在回发一些之后显示错误的值.当隐藏变量或ViewState为空时,错误的值是默认值.

Q#01我应该在哪里调用setButtonScript();方法或我在这里想念的东西.
Q#02为什么hdnCOAGroup.value的值变为空.
请让我知道更多详细信息.谢谢.
在此先感谢
Azhar Iqbal


We set ModuleName property at run time but it shows wrong value after some post backs when it is used to open popup.Wrong Value is default value is set when ever hidden variable or ViewState is empty.

Q#01 where should I call setButtonScript(); method or what I am missing here.
Q#02 Why value of hdnCOAGroup.value become empty.
Please do let me know any further detail Thanks.
Thanks in advance
Azhar Iqbal

推荐答案

感谢Zarif
我已经尝试过
Thanks Zarif
I have tried
if(page.ispostback)
{
 setButtonScript();
}




and

if(!page.ispostback)
{
 setButtonScript();
}



但是,在某些发布之后,返回hdnCOAGroup.Value为空,并返回COAGROUP.F b/c如果条件为真.但是应该执行else部分.
它显示了较早发回的正确值,但问题是为什么隐藏字段的值会变为空以结束发回,



But after some post Back hdnCOAGroup.Value become empty and it return COAGROUP.F b/c If condition become true. But is should execute the else part.
It shows correct value for earlier post back but Problem is that why value of hidden field become empty for ending postback,

if (hdnCOAGroup.Value == "")
               return COAGroup.F;
           else
               return (COAGroup)Enum.Parse(typeof(COAGroup), hdnCOAGroup.Value, true);



为了解决这个问题,我调用了setButtonScript();.
中的方法



To Solve this problem I call the setButtonScript(); method in

set
       {
           _GroupName = value;
           hdnCOAGroup.Value = value.ToString();
           setButtonScript();
       }



但是它会在其他模块b/c中产生脚本问题,许多模块中都使用了相同的代码.
需要进一步的帮助.
谢谢



But It creates scripting problems in other module b/c same code is being used in many module.
Further help is needed.
Thanks


尝试放置:

Try to put :

protected void Page_Load(object sender, EventArgs e)
  {

if(page.ispostback)
{
 setButtonScript();
}
 }


这篇关于postBack之后的值不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆