I am setting the CurrentMode of a FormView to insert mode using the ChangeMode method in the Page_Load event like so:
if(!Page.IsPostBack)
{
MyFormView.ChangeMode(FormViewMode.Insert);
}
Within my FormView's insert template I have a DropDownList control with it's AutoPostBack property set to true. I also have several other DropDownList and TextBox controls within the insert template.
Whenever I change the selection of the DropDownList and a postback occurs I'm losing all the values entered into the controls. The weird thing is that if I use ChangeMode to set the FormView to insert mode anytime after the initial page load I don't have the problem. I've stepped through the the code with the debugger and everything seems to be happening correctly but sometime after my event handler for the DropDownList runs everything seems to be getting reset.
What is going on here?
Update: I noticed that my FormView was inside of a div tag with runat="server" and enableviewstate="false". Once I enabled viewstate for the container div I began seeing a slightly different behavior. The FormView still does not retain values after the first postback but now subsequent postbacks work fine and the values are retained.
Any ideas would be greatly appreciated.