Solved

Set user as active or inactive

Posted on 2008-10-15
7
824 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

25 Experts available now in Live!

Get 1:1 Help Now