在扩展asp.net Web控件时,在哪个事件中注入其他Web控件最合适?
- 内容介绍
- 文章标签
- 相关推荐
本文共计335个文字,预计阅读时间需要2分钟。
我尝试通过扩展现有控件来避免重复合并控件或使用ASCX。然而,我无法将控件添加到继承的控件中并保持其视图状态/完整性。每当我在预渲染期间添加控件时,控件都会显示,但在post-back时会被抛出。
实际上,microsoft说你应该覆盖 CreateChildControls方法.The exception is
Sys.WebForms.PageRequestManagerServerErrorException:
Failed to load viewsstate. The control
tree into which viewstate is being
loaded must match the control tree
that was used to save viewstate during
the previous request. For example,
when adding controls dynamically, the
controls added during a post-back must
match the type and position of the
controls added during the initial
request
你可以在添加控件之前或之后调用基类方法,我不确定那里是否有约定.
protected override void CreateChildControls(){ Controls.Add(someControl); base.CreateChildControls(); }
希望有所帮助!
本文共计335个文字,预计阅读时间需要2分钟。
我尝试通过扩展现有控件来避免重复合并控件或使用ASCX。然而,我无法将控件添加到继承的控件中并保持其视图状态/完整性。每当我在预渲染期间添加控件时,控件都会显示,但在post-back时会被抛出。
实际上,microsoft说你应该覆盖 CreateChildControls方法.The exception is
Sys.WebForms.PageRequestManagerServerErrorException:
Failed to load viewsstate. The control
tree into which viewstate is being
loaded must match the control tree
that was used to save viewstate during
the previous request. For example,
when adding controls dynamically, the
controls added during a post-back must
match the type and position of the
controls added during the initial
request
你可以在添加控件之前或之后调用基类方法,我不确定那里是否有约定.
protected override void CreateChildControls(){ Controls.Add(someControl); base.CreateChildControls(); }
希望有所帮助!

