Domanda

I'm trying to build some simple user controls for a standard ASP.NET membership system. I have a CreateUserWizard control which, when submitted needs to add the user to a particular role.

The ascx file looks like this:

<asp:CreateUserWizard ID="CreateUserWizard2" runat="server" oncreateduser="CreateUserWizard2_CreatedUser">
<WizardSteps>
    <asp:CreateUserWizardStep ID="CreateUserWizard2Step1" runat="server">
        <ContentTemplate>
            <div class="form-error">
                <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
            </div>
            <fieldset class="member-control">
                <legend>Registration details</legend>
                <div class="standard">
                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username&#42;:</asp:Label>
                    <asp:TextBox ID="UserName" runat="server" CssClass="text-input"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="Username is required." ToolTip="Username is required." ValidationGroup="CreateUserWizard1">Username is required.</asp:RequiredFieldValidator>
                </div> ...etc

The C# code-behind looks like this:

namespace DocumentMembership
{
public partial class ClientRegister : System.Web.UI.UserControl
{
    protected void CreateUserWizard2_CreatedUser(object sender, EventArgs e)
    {
        // add member to role
        Roles.AddUserToRole(this.CreateUserWizard2.UserName, "Client");

However, I'm getting a build error saying:

'DocumentMembership.ClientRegister' does not contain a definition for 'CreateUserWizard2' and no extension method 'CreateUserWizard2' accepting a first argument of type 'DocumentMembership.ClientRegister' could be found (are you missing a using directive or an assembly reference?)

When I begin typing Roles.AddUserToRole(this. intellisense doesn't seem to give anything useful to be able to get the username from the form.

I'm really not very skilled at .NET so it's probably something obvious I'm doing wrong, but I just can't seem to find a fix.

Can anyone suggest how to get this working or what might be the issue?

Thanks!

È stato utile?

Soluzione 2

Got it. It was indeed something silly. The ascx file was inheriting from the wrong code-behind, hence it wasn't recognising any method of retrieving the username from the form.

Altri suggerimenti

you can try with this code

CreateUserWizard2.CreateUserStep.ContentTemplateContainer.FindControl("UserName");

if it's about the role assigning try this :

Roles.AddUserToRole((sender as CreateUserWizard).UserName, "LC");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top