So you're using the CSS Friendly Control Adapters to generate lean, mean markup for your asp.net 2.0 controls, awesome! And you're also using some of the new Login controls to cut down on the hand-rolled authentication/authorization code, great. Do you also have ViewState disabled?
Are you also having trouble getting values out of the controls during PostBack processing? I was!
My scenario
I was using the CSS Friendly Control Adapters and the Login controls without ViewState. Specifically I was using the CreateUserWizard and it's ContentTemplate to generate a sleek user registration UI. I had attached a LoginCancelEventHandler to the wizard's CreatingUser event so I could do some custom processing of the entered data, like so:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RegisterNewUser.CreatingUser +=
new LoginCancelEventHandler(RegisterNewUser_CreatingUser);
}
private static void RegisterNewUser_CreatingUser(
object sender, EventArgs e)
{
CreateUserWizard userWizard = (CreateUserWizard) sender;
userWizard.Email = userWizard.UserName;
}
Sorry about he lousy formatting... I was trying to make it blog-friendly.
The problem is userWizard.UserName was returning an empty string, which is odd because the user was created with all of the values (including the user name) I entered on the page. If I turned off the CSS Adapters then everything worked as expected.
WTF?
I did a little reflector-ing and found that the CreateUserWizard control relies on ViewState and apparently that doesn't play well with the CSS Adapters.
Not to worry, there is another way. We need to get the UserName TextBox control from the the wizard's content template's Controls collection, like this:
private static void RegisterNewUser_CreatingUser(
object sender, EventArgs e)
{
CreateUserWizard userWizard = (CreateUserWizard) sender;
TextBox userName = (TextBox)
userWizard.CreateUserStep.ContentTemplateContainer
.FindControl("UserName");
userWizard.Email = userName.Text;
}
I didn't take the time to digĀ into it, but I would guess this is similar to how the Membership provider/control code is wired up - as to avoid the ViewState issues. But I've been wrong before, once. :)
The gist is, you're probably better to use this more invasive code to get the values back out of the Login controls, rather than using the Properties. You could even build a little helper method to save yourself a few keystrokes and provide a hook from some unit testing.