Solved

Set user as active or inactive

Posted on 2008-10-15
7
829 Views
Last Modified: 2013-12-17
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
Comment
Question by:caoimhincryan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 3

Expert Comment

by:sajain84
ID: 22719782
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
 
LVL 3

Expert Comment

by:sajain84
ID: 22719793
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
 

Author Comment

by:caoimhincryan
ID: 22719797
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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 3

Expert Comment

by:sajain84
ID: 22719876
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
 
LVL 3

Accepted Solution

by:
sajain84 earned 500 total points
ID: 22719953
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
 

Author Comment

by:caoimhincryan
ID: 22721356
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
 
LVL 3

Expert Comment

by:sajain84
ID: 22723009
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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question