Error on Membership.DeleteUser

I added a delete button to my gridview that is bound to an ObjectDataSource:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                DataSourceID="UsersInfoDataSource" ForeColor="#333333" GridLines="None" DataKeyNames="UserName">
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <asp:BoundField DataField="UserName" HeaderText="User" ReadOnly="True" SortExpression="UserName" />
                    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                    <asp:TemplateField HeaderText="Approved?">
                            <asp:CheckBox runat="server" OnCheckedChanged="ToggleApproved" AutoPostBack="True" ID="IsApproved" Checked='<%# Eval("IsApproved") %>' />
                    <asp:TemplateField HeaderText="Locked Out?">
                            <asp:CheckBox runat="server" Enabled="False" ID="IsLockedOut" Checked='<%# Eval("IsLockedOut") %>' />
                            <%-- This LinkButton is only shown if the user is locked out --%>
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="UnlockUser" Visible='<%# Eval("IsLockedOut") %>'>Unlock</asp:LinkButton>
                    <asp:TemplateField HeaderText="Administrator?">
                            <asp:CheckBox runat="server" OnCheckedChanged="ToggleAdministrator" AutoPostBack="True" ID="IsAdministrator" Checked='<%# Roles.IsUserInRole(Eval("UserName").ToString(), "Administrator") %>' />
                    <asp:CommandField ButtonType="Button" ShowCancelButton="False"
                        ShowDeleteButton="True" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#2461BF" />
                <AlternatingRowStyle BackColor="White" />
            <asp:ObjectDataSource ID="UsersInfoDataSource" runat="server" SelectMethod="GetAllUsers"
                TypeName="System.Web.Security.Membership" DeleteMethod="DeleteUser"
                    <asp:Parameter Name="username" Type="String" />

Next, I call the RowDeleting event of the GridView
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim user As String = GridView1.DataKeys(e.RowIndex).Values(0).ToString()

        Membership.DeleteUser(user, True)
    End Sub

But I get this error after the delete:
ObjectDataSource 'UsersInfoDataSource' could not find a non-generic method 'DeleteUser' that has parameters: username, original_UserName

But what's funny is the delete is successful. How can I make this delete user call work with no error?
Who is Participating?
Melih SARICAConnect With a Mentor IT ManagerCommented:
onclick event of this link.. but not serverside part for htmlside  

onclick =" return confirm("Do u want to delete user?");"

this script ll run before post back event ..

but u must put  a template field for this u cannot handle that linkbutton with the way u adddelete button
Melih SARICAIT ManagerCommented:
In object data source properties replace orginal_{0} with {0}

Hey techPr

I belive that what's happening is that you try to delete the user twice, (that's not the error though).
As you use the build in delete function will automatically delete the user based on the DeleteMethod and DeleteParameters you have given in the ObjectDataSource. Thus when you catch the OnDeleting event and delete the user your self, Asp.Net will still try to delete the user after this event. The series of events can be seen here.

   OnDeleting (before deletes)
   You delete delete
   OnDeleted  (After deleted)

Now to the error, it looks like you have given wrong paramets in the DeleteParameter part of the ObjectDataSource. there are two ways to fix this, (1) try to se if you can cancle the event (e.handled = true) after you manualy deletede the user. Or (2) don't delete the user manually and give the correct parameters in the DeleteMethod, this can be tricky some times, but maybe try to add a Parameter of the type boolean and set it to True. There is also a (3) third solution, don't use the buildin delete button but add a button your self and catch the click event on that one.

Hope it helps

Melih SARICAIT ManagerCommented:
just change


to OldValuesParameterFormatString="{0}

this ll be ok
techpr0Author Commented:
Great job non_zero, that fixed it right up. And thanks to you also Mighty_Joe, you've helped me understand what's going on better.

non_zero, you're gettin these points but can you show me real quick how to throw a delete confirmation messagebox on this command field (button)? I've never had to do it without a named button.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.