Saturday, March 5, 2011

To delete a user in asp.net


DeleteUserExample.aspx

<%@ Page Language="C#" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  
<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e) {  
        if(!Page.IsPostBack){  
            DropDownListDataBind();  
        }  
    }  
      
    protected void Button1_Click(object sender, System.EventArgs e) {  
        Membership.DeleteUser(DropDownList1.SelectedItem.Text);  
        Label1.Text = "User deleted successfully!";  
        DropDownListDataBind();  
    }  
  
    protected void DropDownListDataBind() {  
        DropDownList1.DataSource = Membership.GetAllUsers();  
        DropDownList1.DataBind();  
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>DeleteUser method example: how to delete a user in asp.net</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>DeleteUser method example</h2>  
        <asp:Label ID="Label1" runat="server" Font-Bold="true" ForeColor="DarkCyan"></asp:Label>  
        <br /><br />  
        <b>Select user</b>  
        <br />  
        <asp:DropDownList ID="DropDownList1" runat="server" BackColor="AliceBlue"></asp:DropDownList>  
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1" Text="*"></asp:RequiredFieldValidator>  
        <br /><br />  
        <asp:Button ID="Button1" runat="server" Text="Delete selected user" OnClick="Button1_Click" />  
    </div>  
    </form>  
</body>  
</html>

No comments: