简体   繁体   中英

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. It's based on the RssFeed ( http://msdn.microsoft.com/en-us/library/aa479322.aspx ) example. 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. The custom composite control overrides CreateChildControls and creates its children. The template is instantiated in a contentplaceholder, with its viewstate enabled. The control, which represents an item is inheriting generic html control and is using a "div" tag. It too has it viewstate enabled. When databinding the composite control trackviewstate is called. Does anyone have idea why the linkbutton is losing its viewstate? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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