Reputation: 739
I'm doing some database manipulation with .NET, using a detailsView of a child element with a hidden field in insert mode to store the parent's ID. It's populated as:
dvChild.ChangeMode(DetailsViewMode.Insert);
HiddenField hdParentId = (HiddenField) FindControlRecursive(Page, "hdParentId");
hdParentId.Value = parent.ParentId;
This works fine initially - the user searches for the parent, the search returns a parent id, the child editor is flipped over to insert mode. On postback I call
dvChild.ChangeMode(DetailsViewMode.ReadOnly);
to use dvChild to echo the original insert.
But when the user runs a search from the postback page, trying to find hdParentId just returns a null, even though the control itself shows up when the page is rendered. What's going on?
FindControlRecursive is the popular hack that drills down through nested controls. dvChild.FindControl("hdParentId") is predictably also coming up empty.
Upvotes: 1
Views: 110
Reputation: 739
Well. I feel silly. I need to call
dvChild.DataBind()
right after the mode change, to guarantee all the variant mode controls will be programatically available.
Upvotes: 1