Solved

Set user as active or inactive

Posted on 2008-10-15
7
823 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
  • 5
  • 2
7 Comments
 
LVL 3

Expert Comment

by:sajain84
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:sajain84
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now