LoadViewState 未在我的用户控件上触发

LoadViewState not fired on my user control(LoadViewState 未在我的用户控件上触发)

本文介绍了LoadViewState 未在我的用户控件上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套在转发器中的用户控件.在我的用户控件中,我有另一个中继器,其中有一个面板.

I have a user control nested in a repeater. Inside my user control I have another repeater and in that I have a panel.

我正在尝试覆盖我的用户控件的 LoadViewState 事件并将控件动态添加到面板.我想在 LoadViewState 中执行此操作,以便在加载视图状态之前添加动态控件,以便它们在回发后保留其值.

I am trying to override the LoadViewState event of my user control and dynamically add controls to the panel. I want to do it in the LoadViewState so that the dynamic controls get added before the viewstate gets loaded, so they retain their values after post backs.

由于某种原因,用户控件 (ascx) 上的 LoadViewState 事件未触发.有什么方法可以强制它开火,还是我可以使用另一种方法?我已经排除了用户控件转发器数据绑定事件,因为即使没有发生数据绑定,我也需要它工作,而且我也无法在转发器项目创建事件上执行此操作,因为子面板和内部 html 不存在还没有.

For some reason the LoadViewState event on the user control (ascx) is not firing. Is there some way to force it to fire, or is there another method I could use? I have ruled out the user controls repeater databind event, because I need it to work even if data binding isn't happening and I can't do it on the repeaters item created event either because the child panel and inner html doesn't exist yet.

推荐答案

LoadViewState 不适合添加子控件.要在用户控件中动态添加控件,您需要查看 CreateChildControls 方法.

LoadViewState isn't the appropriate place for adding child controls. For dynamically adding controls within a user control, you'll want to look at the CreateChildControls method.

它不会触发 LoadViewState 事件,因为您需要在 ViewState 中至少保存一个值才能触发事件.

It's not firing a LoadViewState event because you need to save at least one value in the ViewState to have the event fire.

这篇关于LoadViewState 未在我的用户控件上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:LoadViewState 未在我的用户控件上触发

基础教程推荐