简体   繁体   English

ASP.NET自定义复合控件模板中的Linkbutton失去其ViewState

[英]Linkbutton inside ASP.NET custom composite control template losing its ViewState

I've made an ASP.NET custom composite control which has an ItemTemplate for its children. 我已经制作了一个ASP.NET自定义复合控件,该控件具有用于其子项的ItemTemplate。 It's based on the RssFeed ( http://msdn.microsoft.com/en-us/library/aa479322.aspx ) example. 它基于RssFeed( http://msdn.microsoft.com/en-us/library/aa479322.aspx )示例。 The template has a linkbutton which binds commandname and commandargument to properties in the datasource. 该模板具有一个链接按钮,该按钮将命令名和命令参数绑定到数据源中的属性。 On postback the commandname and commandargument are empty, and the text of the linkbutton disappears after the rendering on postback. 在回发时,命令名和命令参数为空,并且在回发呈现后,链接按钮的文本消失。 This leads me to believe that linkbutton is losing its viewstate. 这使我相信linkbutton正在丢失其视图状态。 The custom composite control overrides CreateChildControls and creates its children. 自定义复合控件将覆盖CreateChildControls并创建其子级。 The template is instantiated in a contentplaceholder, with its viewstate enabled. 模板在contentplaceholder中实例化,并启用了viewstate。 The control, which represents an item is inheriting generic html control and is using a "div" tag. 表示项目的控件继承了通用html控件,并使用“ div”标签。 It too has it viewstate enabled. 它也启用了viewstate。 When databinding the composite control trackviewstate is called. 进行数据绑定时,将调用复合控件trackviewstate。 Does anyone have idea why the linkbutton is losing its viewstate? 有谁知道为什么linkbutton失去了它的视图状态? Thanks 谢谢

I've found the mistake I've made. 我发现了我犯的错误。 When I was creating my children items I was adding them to their parent. 在创建子项时,我将它们添加到其父项中。 Then I was databinding them, but the problem was that their parent was not added to the control hierarchy and so ViewState tracking was never turned on. 然后我对它们进行数据绑定,但是问题是它们的父级没有添加到控件层次结构中,因此从未打开ViewState跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM