详细信息视图重置绑定可见性?
我正在使用实体框架 4.0 将数据库对象绑定到 ascx 控件上的 DetailsView。在DetailsView 中,我有许多asp:panels,我想根据该人的访问中发生的情况来显示/隐藏它们。
因此,第一次浏览该页面时,我在 FormView_OnLoad 事件中设置 panelA.Visible=false,一切都很好 - 该面板不会在 HTML 中输出。它听我在这里问什么。
单击提交和回发后,我将再次检查发生的情况并在 FormView_OnLoad 和 EntityData_OnUpdating 中设置 panelA.Visibe=false。但这一次,当页面出现时,将显示 panelA。
我发现只能通过在DetailsView_PreRender 中设置visible=false 或将可见性绑定到公共变量来在回发后隐藏该面板。
我想也许在生命周期中,DetailsView 具有绑定性再次接近尾声,并丢弃我的可见性设置,即使它们没有绑定。因此,要在回发时显示/隐藏DetailsView 中的面板,我是否始终必须在DetailsView_PreRender 或之后设置可见性?
我是否走在正确的轨道上,还是有其他东西在最后一秒重置了我?
为什么我可以设置第一次浏览页面的可见性但不能设置回发?
I am using entity framework 4.0 to bind a database object to a DetailsView on an ascx control. Within the DetailsView, I have a number of asp:panels that I'd like to show/hide depending on what's happening in that person's visit.
So, the first time through the page I'm setting panelA.Visible=false in the FormView_OnLoad event, and all is well - that panel is not output in the HTML. It listens to what I'm asking here.
Once I click submit and postback, I am again checking what's going on and setting panelA.Visibe=false in both FormView_OnLoad and EntityData_OnUpdating. But this time, when the page comes up panelA is showing.
I find that I can only hide that panel after postback by setting visible=false in DetailsView_PreRender, or by binding visibility to a public variable.
I'm thinking perhaps in the life cycle the DetailsView is binding again way toward the end, and throws away my visibility settings, even though they're not bound. So to show/hide panels within the DetailsView on postback, will I always have to set visibility on DetailsView_PreRender or after?
Am I on the right track here, or is something else resetting me at the last second?
Why can I set visibility the first time through the page but not postback?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该始终在回发处理后对页面结构进行最终修改 - 这就是
PreRender
事件存在的原因。您的场景中其他可能的事件可以是处理 DataBound 事件,但更好、更清晰的方法是PreRender
。You should always make final modification of your page structure after postback processing - that is the reason why
PreRender
event exists. Other possible event in your scenario can be handling DataBound event but better and more clear way isPreRender
.