[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Set user as active or inactive

Posted on 2008-10-15
7
Medium Priority
?
835 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 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