Posted by ikaruga as ASP.NET
To assign a role to a new user, we usually use the following code. We call this on the CreatedUser event of the ASP.NET CreateUserWizard Control:
protected void CreatedUser(object sender, EventArgs e) {
Roles.AddUserToRole(cuwRegister.UserName, “Registered User”);
}
The code worked fine for me but not when I customized the CreateUserWizard Control where I encountered this error:
The parameter ‘username’ must not be empty.
Parameter name: username
For some reason, the cuwRegister.UserName gives an empty string thus the error. So I used the FindControl method to access the UserName textbox:
TextBox userName = (TextBox)cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl(”UserName”);
Roles.AddUserToRole(userName.Text, “Registered User”);
To learn how to customize the CreateUserWizard Control, go to MSDN.
Tags: asp .net tutorial
.Net asp .net tutorial asp .net tutorial c# sample code CSS sample script database guide java sample code javascript sample code mssql sample script string reverse in C# t-sql telerik sample code user-defined function vb .net sample code visual studio tutorial
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.