ASP.NET 2 LoginView Inside FormView Data Binding Problem
I was recently working on an ASP.NET 2 application which uses the SQL Membership Provider for User Role Management. While customising the output of the forms in the admin area using the LoginView I encountered a bug in asp.net 2. This bug wasted a lot of time debugging and scratching my head wondering what was wrong.
For some reason all the controls that I had moved into a LoginView were no longer binding to the DataSource used by the FormView. I spent a lot of time looking for an answer on Google and the only post I could find about this problem is:
LoginView not showing databound controls
http://social.expression.microsoft.com/Forums/en-US/web/thread/676ca185-6ff6-4419-b79b-102cbd1a7314/
This post identifies the problem occurs when an edit, delete or insert operation is performed on the FormView.
This led to to my work around for the problem:
Instead of using the command buttons provided by the FormView to change its mode I replaced the form view command buttons with standard buttons with the following code behind:
Dim strURL As String = “EditScript.aspx”
If Request.QueryString(“sid”) <> “” Then
strURL &= “?sid=” & Request.QueryString(“sid”) & “&method=edit”
End If
Response.Redirect(strURL)
End Sub
Instead of just changing the FormViews CurrentMode the button handler redirects to the script with a couple of query string parameters to tell the form what behaviour is required.
The page_load event then checks these query strings and modifies the FormView accordingly, when using this method to change the FormViews mode the databndings will display the data bound to them inside the LoginView controls.
Because the two-way binding is also affected for controls inside the LoginView, the next step is to intercept the FormViews updating, inserting, deleting events etc to load the value from the LoginViews into the DataSources parameters.
I haven’t had time to experiment with alternatives such as changing the FormView.CurrentMode in the handler instead of redirecting but if anyone knows of a neater solution then please post comments.
If you need code samples for the rest of my work around then please let me know.

