I cannot change control's visibility on C# code

我怕爱的太早我们不能终老 提交于 2019-12-13 07:12:35

问题


I want to change controls visibility on c#, but nothing happens. The controls are in an AspxPopupControl and 3 of them are hidden in design time, 1 of them is visible. I use this code to visible them

if (paramType == "Grup")
            {
                gv_Answers.Visible = false;
                trlGroup.Visible = true;
                chkShowItems.Visible = true;

            }
            else
            {
                gv_Answers.Visible = true;
                trlGroup.Visible = false;
                chkShowItems.Visible = false;
            }

This code is in a CustomCallBack event of a gridview. So i don't know what to do from this point. It's an easy task but i couldn't handle it.

Thanks for you helps


回答1:


The cause of this problem is that you are changing the control's visibility within the ASPxGridView's callback. The callback response contains only the information about control who initiated the callback and its child controls. Since the ASPxPopupControl is not a part of the GridView, the problem appears. The easiest solution is to implement this code within a PostBack event, not a callback. In this case, everything will work correctly.




回答2:


Please change the order your code is executed:

trlGroup.DataSource = gnlTreeDColl;
trlGroup.DataBind();
trlGroup.ExpandAll();

This should work.




回答3:


Change the GridView enableCallback property to False.



来源:https://stackoverflow.com/questions/3862397/i-cannot-change-controls-visibility-on-c-sharp-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!