Hej, har ett litet problem efter att läst en mycket bra artikel på http://www.pellesoft.se/area/articles/article.aspx?artid=975 som beskriver det jag vill uppnå. Postar här lite kod... hmm...ett litet stavfel hade smugit sig in... (=MySqlMembershipProvider - Lägga till egna parametrar
CreateUser.cs (codebehind)
<code>
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
// Get First- and Last name
TextBox txtFirstName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName");
TextBox txtLastName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName");
TextBox txtAddress = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Address");
TextBox txtPaddress = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Paddress");
TextBox txtPhoneHome = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("PhoneHome");
TextBox txtMobilPhone = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("MobilPhone");
TextBox userNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
TextBox Email = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
// Cast the user object of the GetUser() method to
// be of type MySQLMembershipUser
IFK.MySQLMembershipUser user = (IFK.MySQLMembershipUser)Membership.GetUser(userNameTextBox.Text);
// Add additional data
user.FirstName = txtFirstName.Text;
user.LastName = txtLastName.Text;
user.Address = txtAddress.Text;
user.Paddress = txtPaddress.Text;
user.PhoneHome = txtPhoneHome.Text;
user.MobilePhone = txtMobilPhone.Text;
// Update the user in the database
Membership.UpdateUser(user);
}
</code>
MembershipUser.cs
<code>
using System;
using System.Web.Security;
/// <summary>
/// STYR ÖVER KLASSEN MembershipUser MED EGNA PARAMETERAR
/// </summary>
///
namespace IFK
{
public class MySQLMembershipUser : MembershipUser
{
/* ==============================================
* EGENSKAPER SOM UTÖKAR BAS KLASSEN (MEMBERSHIP)
* ============================================== */
private string _FirstName;
private string _LastName;
private string _Address;
private string _Paddress;
private string _PhoneHome;
private string _MobilePhone;
public string FirstName
{
get { return _FirstName; }
set { _FirstName = value; }
}
public string LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public string Address
{
get { return _Address; }
set { _Address = value; }
}
public string Paddress
{
get { return _Paddress; }
set { _Paddress = value; }
}
public string PhoneHome
{
get { return _PhoneHome; }
set { _PhoneHome = value; }
}
public string MobilePhone
{
get { return _MobilePhone; }
set { _MobilePhone = value; }
}
public MySQLMembershipUser(string providername,
string username,
object providerUserKey,
string email,
string passwordQuestion,
string comment,
bool isApproved,
bool isLockedOut,
DateTime creationDate,
DateTime lastLoginDate,
DateTime lastActivityDate,
DateTime lastPasswordChangedDate,
DateTime lastLockedOutDate,
string firstname,
string lastname,
string address,
string padress,
string phonehome,
string mobilephone)
:
base(providername,
username,
providerUserKey,
email,
passwordQuestion,
comment,
isApproved,
isLockedOut,
creationDate,
lastLoginDate,
lastActivityDate,
lastPasswordChangedDate,
lastLockedOutDate)
{
this.FirstName = firstname;
this.LastName = lastname;
this.Address = address;
this.Paddress = padress;
this.PhoneHome = phonehome;
this.MobilePhone = mobilephone;
}
}
}
</code>
MySqlMembershipProvider.cs
<code>
...
public override MembershipUser CreateUser(string username,
string password,
string email,
string passwordQuestion,
string passwordAnswer,
bool isApproved,
object providerUserKey,
out MembershipCreateStatus status)
{
// RETURNERAR METODEN
return this.CreateUser("", "", "", "", "", "",
username,
password,
email,
passwordQuestion,
passwordAnswer,
isApproved,
providerUserKey,
out status);
}
/// <summary>
/// DEN ÖVERSTYRDA METODEN SKAPAR EN MEDLEM TILL Membership OCH TAR GIVNA PARAMETRAR (KONTAKTINFO)
/// SÅSOM FÖRNAMN,EFTERNAMN,ADRESS,TELEFON MM
/// </summary>
/// <returns>MySqlMembershipUser object</returns>
public MySQLMembershipUser CreateUser(string FirstName,
string LastName,
string Address,
string Paddress,
string PhoneHome,
string MobilePhone,
string username,
string password,
string email,
string passwordQuestion,
string passwordAnswer,
bool isApproved,
object providerUserKey,
out MembershipCreateStatus status)
{
...
// TILLÄGG PARAMETERAR (KONTAKTINFORMATION)
cmd.Parameters.Add("?MemberFirstName", MySqlDbType.VarChar, 50).Value = FirstName;
cmd.Parameters.Add("?MemberLastName", MySqlDbType.VarChar, 50).Value = LastName;
cmd.Parameters.Add("?MemberAddress", MySqlDbType.VarChar, 50).Value = Address; ;
cmd.Parameters.Add("?MemberPostalAddress", MySqlDbType.VarChar, 50).Value = Paddress;
cmd.Parameters.Add("?MemberPhone", MySqlDbType.VarChar, 50).Value = PhoneHome;
cmd.Parameters.Add("?MemberMobilePhone", MySqlDbType.VarChar, 50).Value = MobilePhone;
...
</code>
Problemet är att ingenting skickas från formuläret (textboxarna) förnamn, efternamn osv. Jag får bara "" i debuggern och tomma fält vid insättning i databasen utom username, email mm. Jag har för närvarande inga ideér om vad det kan vara eller vad jag ska göra?
Tacksam för hjälp
MichaelSv: MySqlMembershipProvider - Lägga till egna parametrar