Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

Set user as active or inactive

Do you know is it possible to set a user as active or inactive from an aspx page?

Try get something similar like in the asp.net configuration page under security?
0
caoimhincryan
Asked:
caoimhincryan
  • 5
  • 2
1 Solution
 
sajain84Commented:
Yes. This is possible.

All we do is make the user's account inactive by setting his IsApproved property to false.
Again, in the wzdRegister_CreatedUser event, you do the following:

MembershipUser user = Membership.GetUser(wzdRegister.UserName);
user.IsApproved = false;
Membership.UpdateUser(user);

Open in new window

0
 
sajain84Commented:
Forgot to add:
By doing this, the user will not be able to login to the system until you set the property to true again.

We use this all the time to verify someone's email address.
We send an email with a link on clicking which, we set the IsApproved property to true.
0
 
caoimhincryanAuthor Commented:
Sorry, I should have explained...

I want to be able to come in and look at all my users on a page and then decide to set a user as inactive or active?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
sajain84Commented:
Ok. :)

What you need to do is this:

Drag and drop a grid onto the page - lets call it grid1.
Then do this in your Page_Load (see code below)

---
This will give you a quick and dirty way to see all members.
You can then go ahead and edit the grid and add the Select buttons and write code behind to select certain users and change their properties, etc.

Let me know if this helps and whether you need help with something more specific.

grid1.DataSource = Membership.GetAllUsers();
grid1.DataBind();

Open in new window

0
 
sajain84Commented:
A quick way to enable / disable and account using the grid would be as follows:

1. Go to the designer view.
2. Click on the top-right corner arrow which gets displayed when the grid is selected.
3. Add a new template field
4. Drop in a button into that template field
5. Go to your code view of the aspx page and change your button so that it looks something like this: (See section 1)
6. Then go to your code behind file (cs) and do this: (Section 2)

PS: You would also want to turn the EventValidation Property of your page to false - otherwise the page will break.
Go to the aspx page and make sure the header looks something like this: (Section 3)

// Section1 - Your aspx page button in the grid
<asp:Button ID="Button4" runat="server" CommandArgument='<%# Eval("ProviderUserKey") %>' OnCommand="Button4_Command" Text="Toggle Account" />
 
// Section 2 - Your code behind file
protected void Button4_Command(object sender, CommandEventArgs e) {
Guid id = new Guid(e.CommandArgument.ToString());
MembershipUser user = Membership.GetUser(id);
 
if (user.IsApproved) {
   user.IsApproved = false;
}
else {
   user.IsApproved = true;
}
 
Membership.UpdateUser(user);
}
 
// Section 3 - Your aspx page header
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" EnableEventValidation="false" Inherits="Test" %>

Open in new window

0
 
caoimhincryanAuthor Commented:
I cant seem to drop a button into the template field.

Error      18      Element 'Button' is not a known element. This can occur if there is a compilation error in the Web site.      

<asp:TemplateField>
                    <asp:Button runat="server" Text="Button" />
                </asp:TemplateField>

Open in new window

0
 
sajain84Commented:
Thats strange. Can you tell me which version of ASP.Net are you using?
I was assuming you are using .Net 2 or Visual Studio 2005.

Incase you are, your grid should look something like this: (See code below)
(You might have missed the ID attribute)

    <asp:GridView ID="grdUsers" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="Button4" runat="server" CommandArgument='<%# Eval("ProviderUserKey") %>' OnCommand="Button4_Command" Text="Toggle Account" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now