asp.net - Membership.Updateuser not really updating the database -
i'm working on membership system web application, based on forms authentication framework.
i created users integrated tool, , login working. want give administrator capability create, modify, delete users.
so here i've got right now:
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load dim muc membershipusercollection = membership.getallusers() combobox1.datasource = muc combobox1.datavaluefield = "username" combobox1.datatextfield = "username" combobox1.databind() end sub protected sub combobox1_selectedindexchanged(byval sender object, byval e eventargs) handles combobox1.selectedindexchanged dim username string = combobox1.selectedvalue dim mu membershipuser = membership.getuser(username) dim userroles string() = roles.getrolesforuser(username) tbcomments.text = mu.comment tbemail.text = mu.email lblusername.text = mu.username end sub protected sub button1_click(byval sender object, byval e eventargs) handles button1.click dim username string = combobox1.selectedvalue dim mu membershipuser = membership.getuser(username) if not mu nothing try mu.comment = tbcomments.text membership.updateuser(mu) mu.email = tbemail.text membership.updateuser(mu) mu.isapproved = true membership.updateuser(mu) mu = nothing catch ex exception console.writeline(ex.tostring()) end try end if detailpanel.visible = false end sub
the problem record doesn't seem updated in database. made multiple calls membership.updateuser
after reading this blog entry, didn't change anything.
a strange thing noticed while debugging, when enter button1_click
method, membership.getuser(username)
returns me values precedent attempt ! don't understand i'm missing.
does have clue ?
thanks in advance !
first:
the blog entry cite wrong.
here method calling, tell me if see indication needs called multiple times update multiple properties:
public override void updateuser(membershipuser user) { if (user == null) { throw new argumentnullexception("user"); } secutility.checkparameter(ref user.username, true, true, true, 0x100, "username"); string email = user.email; secutility.checkparameter(ref email, this.requiresuniqueemail, this.requiresuniqueemail, false, 0x100, "email"); user.email = email; try { sqlconnectionholder connection = null; try { connection = sqlconnectionhelper.getconnection(this._sqlconnectionstring, true); this.checkschemaversion(connection.connection); sqlcommand command = new sqlcommand("dbo.aspnet_membership_updateuser", connection.connection); command.commandtimeout = this.commandtimeout; command.commandtype = commandtype.storedprocedure; command.parameters.add(this.createinputparam("@applicationname", sqldbtype.nvarchar, this.applicationname)); command.parameters.add(this.createinputparam("@username", sqldbtype.nvarchar, user.username)); command.parameters.add(this.createinputparam("@email", sqldbtype.nvarchar, user.email)); command.parameters.add(this.createinputparam("@comment", sqldbtype.ntext, user.comment)); command.parameters.add(this.createinputparam("@isapproved", sqldbtype.bit, user.isapproved ? 1 : 0)); command.parameters.add(this.createinputparam("@lastlogindate", sqldbtype.datetime, user.lastlogindate.touniversaltime())); command.parameters.add(this.createinputparam("@lastactivitydate", sqldbtype.datetime, user.lastactivitydate.touniversaltime())); command.parameters.add(this.createinputparam("@uniqueemail", sqldbtype.int, this.requiresuniqueemail ? 1 : 0)); command.parameters.add(this.createinputparam("@currenttimeutc", sqldbtype.datetime, datetime.utcnow)); sqlparameter parameter = new sqlparameter("@returnvalue", sqldbtype.int); parameter.direction = parameterdirection.returnvalue; command.parameters.add(parameter); command.executenonquery(); int status = (parameter.value != null) ? ((int) parameter.value) : -1; if (status != 0) { throw new providerexception(this.getexceptiontext(status)); } } { if (connection != null) { connection.close(); connection = null; } } } catch { throw; } }
second:
you rebinding list every postback. needs done once , list stored in viewstate.
here working implementation:
updateuser.aspx
<%@ page language="vb" %> <script runat="server"> protected sub page_load(byval sender object, byval e system.eventargs) handles me.load ' sure dropdownlist1.autopostback = true if not ispostback binduserlist() end if end sub private sub combobox1_selectedindexchanged(byval sender object, byval e eventargs) handles combobox1.selectedindexchanged displaydetails(combobox1.selectedvalue) end sub private sub button1_click(byval sender object, byval e eventargs) handles button1.click dim approved boolean = true dim username string = combobox1.selectedvalue dim comments string = tbcomments.text dim email string = tbemail.text updateuser(username, approved, comments, email) end sub private sub binduserlist() '' need databind once, datasource stored in viewstate dim muc membershipusercollection = membership.getallusers() combobox1.datasource = muc combobox1.datavaluefield = "username" combobox1.datatextfield = "username" combobox1.databind() '' initialize selection combobox1_selectedindexchanged(combobox1, eventargs.empty) end sub private sub displaydetails(byval username string) dim mu membershipuser = membership.getuser(username) dim userroles string() = roles.getrolesforuser(username) tbcomments.text = mu.comment tbemail.text = mu.email lblusername.text = mu.username end sub private sub updateuser(byval username string, byval approved boolean, byval comments string, byval email string) dim mu membershipuser = membership.getuser(username) if not mu nothing try mu.comment = comments mu.email = email mu.isapproved = approved membership.updateuser(mu) errlabel.text = "" catch ex exception errlabel.text = ex.message end try end if end sub </script> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:dropdownlist id="combobox1" runat="server" autopostback="true"> </asp:dropdownlist> </div> <p> username:<asp:label id="lblusername" runat="server" text=""></asp:label><br /> email:<asp:textbox id="tbemail" runat="server"></asp:textbox><br /> comments:<asp:textbox id="tbcomments" runat="server"></asp:textbox><br /> </p> <asp:button id="button1" runat="server" text="update" height="26px" width="61px" /><br /> <asp:label id="errlabel" runat="server" text=""></asp:label> </form> </body> </html>
Comments
Post a Comment