You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Ektron.Cms.API.User Namespace > Classes > User Class > User Methods > AddMembershipUser
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
User.AddMembershipUser Method

Adds a new membership user to CMS.

C#
public UserData AddMembershipUser(UserData udUserData);
Visual Basic
Public Function AddMembershipUser(ByVal udUserData As UserData) As UserData
Parameters 
Description 
udUserData 
An object of class which represents the corresponding user elements. 

Ektron.Cms.UserData

The following example shows how to create a Web page from which a new membership user can be added. This example uses some standard drag and drop controls and a small section of VB code utilizing the AddMembershipUser method. This method uses the InternalAdmin to add the Membership User. In the first section, we will deal with the standard drag and drop controls. In the second, we'll deal with the code behind. 

 

  1. Between the form tags, create a table with four rows and three columns.
  2. In the first row, first column, add a label that shows where to enter the membership user's Email address.
       <asp:Label ID="Label6" runat="server" Text="Email: " Width="76px"></asp:Label>
  3. In the first row, second column, add a text box to enter the Email address.
       <asp:TextBox ID="txtEmail" runat="server" Width="144px"></asp:TextBox>
  4. In the first row, third column, add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the Email address box.
       <asp:RequiredFieldValidator ID="rfvEmail" runat="server" ErrorMessage="Please enter an Email address"
             ControlToValidate="txtEmail" Display="Dynamic">Please enter email address</asp:RequiredFieldValidator>
  5. In the same table cell, add a RegularExpressionValidator control. This validates the information entered is in the format of an Email address.
       <asp:RegularExpressionValidator ID="rfvEmailFormat" ControlToValidate="txtEmail" runat="server" ErrorMessage="Please enter a valid email address" 
           ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Width="236px" ></asp:RegularExpressionValidator>
  6. In the second row, first column, add a label to show where to enter a first name.
       <asp:Label ID="Label4" runat="server" Text="First name: " Width="76px"></asp:Label>
  7. In the second row, second column, add a text box to enter the fist name.
       <asp:TextBox ID="txtFirstName" runat="server" Width="144px"></asp:TextBox>
  8. In the second row, third column, add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the first name box.
       <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ErrorMessage="Please enter first name" 
            ControlToValidate="txtFirstName">Please enter first name</asp:RequiredFieldValidator>
  9. In the third row, first column, add a label to show where to enter a last name. 
       <asp:Label ID="Label7" runat="server" Text="Last Name:" Width="76px"></asp:Label>
 10. In the third row, second column, add a text box to enter the last name.
       <asp:TextBox ID="txtLastName" runat="server" Width="144px"></asp:TextBox>
 11. In the third row, third column, add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the last name box.
       <asp:RequiredFieldValidator ID="rfvLastName" runat="server" ErrorMessage="Please enter last name" 
             ControlToValidate="txtLastName">Please enter last name</asp:RequiredFieldValidator>
 12. In the fourth row, first column, add a label to show where to enter a password.
       <asp:Label ID="Label8" runat="server" Text="Password: " Width="76px"></asp:Label>
 13. In the fourth row, second column, add a text box to enter the password.
       <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="144px"></asp:TextBox>
 14. In the fourth row, third column,  add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the password box.
       <asp:RequiredFieldValidator ID="rfvPassword" runat="server" ErrorMessage="Please enter password"
               ControlToValidate="txtPassword">Please enter password</asp:RequiredFieldValidator>
 15. After the table, add a break and then add a button to submit the membership user's information.
       <br />
       <asp:Button ID="btnAdd" runat="server" Text="Add Membership User" Width="153px" />
 16. Add two breaks for spacing purposes.
      <br /><br />
 17. Add a results label to display a message stating the membership user was added and the new ID.
      <asp:Label ID="lblResult" runat="server"></asp:Label>

 

Add the following information to the code behind of your aspx.vb page.

  1. Add button click event.

       Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click

  1. Create an object for the user data items.

          Dim memDetails As New Ektron.Cms.UserData

  1. Create an object for the new membership user information.

          Dim newMemUser As New Ektron.Cms.UserData

  1. Create an object for the User API.

          Dim userAPI As New Ektron.Cms.API.User.User

  1. Create an integer place holder for the new ID.

          Dim newMemUserId As Integer

  1. Populate memDetails with the information from the text boxes.

          memDetails.Username = txtEmail.Text
          memDetails.FirstName = txtFirstName.Text
          memDetails.LastName = txtLastName.Text
          memDetails.Password = txtPassword.Text

  1. Create a Try/Catch around the AddMembershipUser method. This allows you to catch any exceptions and helps when debugging.

          Try
              newMemUser = userAPI.AddMembershipUser(memDetails)

  1. Assign newMemUserId a new ID.

              newMemUserId = newMemUser.Id

  1. Check to see if there is an ID returned. If so, display a message with the membership username and ID.

           If (newMemUserId > 0) Then
               lblResult.Text = "The membership user " & txtEmail.Text & " was added into CMS400.Net with UserID = " & newMemUserId
           End If   

  1. If there is an error, let the user know what happened.

           Catch ex As Exception
              lblResult.Text = ex.Message
           End Try
 
    End Sub
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at [email protected].
Copyright (c) 2008. All rights reserved.
What do you think about this topic? Send feedback!