mathieu_cupryk
asked on
An Object reference is required for the non-static filed, method, or property
Error 42 An object reference is required for the non-static field, method, or property 'DateDLL.DateDDL.Date.get' C:\inetpub\wwwroot\OmegaLo ve\OmegaLo ve.Web\Con trols\uxRe gister.asc x.cs 75 67 OmegaLove.Web
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
using System;
using System.Collections.Generic ;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OL_DateDLL
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:DateDDL runat=server></{0}:DateDDL >")]
public class OL_DateDDL : CompositeControl
{
private Label lblCaption = new Label();
private Label lblCaptionPadding = new Label();
private DropDownList ddlMonth = new DropDownList();
private DropDownList ddlDay = new DropDownList();
private DropDownList ddlYear = new DropDownList();
private string caption;
private Unit captionWidth;
private Unit captionPadding;
private bool rightAlignCaption;
private int month;
private int day;
private int year;
private bool autoPostBack;
private bool dateChangedEventRaised = false;
public event EventHandler DateChanged;
public OL_DateDDL()
{
ddlDay.SelectedIndexChange d += new EventHandler(ddlDay_Select edIndexCha nged);
ddlMonth.SelectedIndexChan ged += new EventHandler(ddlMonth_Sele ctedIndexC hanged);
ddlYear.SelectedIndexChang ed += new EventHandler(ddlYear_Selec tedIndexCh anged);
month = DateTime.Today.Month;
day = DateTime.Today.Day;
year = DateTime.Today.Year;
}
[Category("Appearance")]
[Description("The caption displayed to the left of the text box.")]
public string Caption
{
get { return caption; }
set { caption = value; }
}
[Category("Appearance")]
[Description("The width of the caption.")]
public Unit CaptionWidth
{
get { return captionWidth; }
set { captionWidth = value; }
}
[Category("Appearance")]
[Description("The space between the caption and the text box.")]
public Unit CaptionPadding
{
get { return captionPadding; }
set { captionPadding = value; }
}
[Category("Appearance")]
[Description("Determines if the caption is right-aligned.")]
public bool RightAlignCaption
{
get { return rightAlignCaption; }
set { rightAlignCaption = value; }
}
public DateTime Date
{
get
{
DateTime date;
// Attempt to parse the date
if (!DateTime.TryParse(this.M onth + "/" + this.Day + "/" + this.Year, out date))
{
// Invalid date! return MinValue
date = DateTime.MinValue;
}
return date;
}
set
{
this.Month = value.Month;
this.Day = value.Day;
this.Year = value.Year;
}
}
// Add this to the DateDDL class somewhere
protected virtual void OnDateChanged(EventArgs e)
{
// Trigger the event if it's defined,
// and we haven't triggered it already.
if (!dateChangedEventRaised && DateChanged != null)
{
DateChanged(this, e);
dateChangedEventRaised = true; // Don't trigger more than once.
}
}
// Change the property definitions in DateDDL as follows:
[Category("Misc"), Description("Gets or set the month.")]
public int Month
{
get
{
month = ddlMonth.SelectedIndex + 1;
return month;
}
set
{
month = value;
ddlMonth.SelectedIndex = month - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the day.")]
public int Day
{
get
{
day = ddlDay.SelectedIndex + 1;
return day;
}
set
{
day = value;
ddlDay.SelectedIndex = day - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the year.")]
public int Year
{
get
{
year = Convert.ToInt32(ddlYear.Se lectedValu e);
return year;
}
set
{
year = value;
ddlYear.SelectedValue = year.ToString();
OnDateChanged(new EventArgs());
}
}
[Category("Misc")]
[Description("Determines whether a postback occurs "
+ "when the selection is changed.")]
[DefaultValue(false)]
public bool AutoPostBack
{
get { return autoPostBack; }
set { autoPostBack = value; }
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
protected override void CreateChildControls()
{
this.MakeCaption();
this.MakeCaptionPadding();
this.MakeMonthList();
this.MakeDayList();
this.MakeYearList();
Controls.Clear();
Controls.Add(lblCaption);
Controls.Add(lblCaptionPad ding);
Controls.Add(ddlMonth);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlDay);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlYear);
// Register client script:
ddlMonth.Attributes.Add("o nchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
ddlDay.Attributes.Add("onc hange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
ddlYear.Attributes.Add("on change", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
}
private void MakeCaption()
{
lblCaption.Text = Caption;
lblCaption.Width = CaptionWidth;
if (RightAlignCaption)
lblCaption.Style["text-ali gn"] = "right";
}
private void MakeCaptionPadding()
{
lblCaptionPadding.Width = CaptionPadding;
}
private void MakeMonthList()
{
ddlMonth.Width = Unit.Pixel(85);
ddlMonth.Items.Clear();
ddlMonth.Items.Add("Januar y");
ddlMonth.Items.Add("Februa ry");
ddlMonth.Items.Add("March" );
ddlMonth.Items.Add("April" );
ddlMonth.Items.Add("May");
ddlMonth.Items.Add("June") ;
ddlMonth.Items.Add("July") ;
ddlMonth.Items.Add("August ");
ddlMonth.Items.Add("Septem ber");
ddlMonth.Items.Add("Octobe r");
ddlMonth.Items.Add("Novemb er");
ddlMonth.Items.Add("Decemb er");
ddlMonth.AutoPostBack = AutoPostBack;
ddlMonth.SelectedIndex = Month - 1;
}
private void MakeDayList()
{
ddlDay.Width = Unit.Pixel(40);
ddlDay.Items.Clear();
for (int i = 1; i <= 31; i++)
ddlDay.Items.Add(i.ToStrin g());
ddlDay.SelectedValue = Day.ToString();
ddlDay.AutoPostBack = AutoPostBack;
}
private void MakeYearList()
{
ddlYear.Width = Unit.Pixel(65);
ddlYear.Items.Clear();
for (int i = DateTime.Today.Year - 100;
i <= DateTime.Today.Year - 18; i++)
ddlYear.Items.Add(i.ToStri ng());
ddlYear.SelectedValue = Year.ToString();
ddlYear.AutoPostBack = AutoPostBack;
}
private void ddlMonth_SelectedIndexChan ged(object sender, EventArgs e)
{
this.Month = ddlMonth.SelectedIndex + 1;
this.AdjustDay();
}
private void ddlDay_SelectedIndexChange d(object sender, EventArgs e)
{
this.Day = Convert.ToInt32(ddlDay.Sel ectedValue );
this.AdjustDay();
}
private void ddlYear_SelectedIndexChang ed(object sender, EventArgs e)
{
this.Year = Convert.ToInt32(ddlYear.Se lectedValu e);
this.AdjustDay();
}
// C# Code behind in DateDDL class:
private void AdjustDay()
{
switch (Month)
{
case 4:
case 6:
case 9:
case 11:
if (Day > 30) Day = 30;
break;
case 2:
int yy = Year;
if (Day > 28)
Day = (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) ? 29 : 28;
break;
}
}
}
}
--------------------------
using System;
using System.Collections.Generic
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OL_DateDLL
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:DateDDL
public class OL_DateDDL : CompositeControl
{
private Label lblCaption = new Label();
private Label lblCaptionPadding = new Label();
private DropDownList ddlMonth = new DropDownList();
private DropDownList ddlDay = new DropDownList();
private DropDownList ddlYear = new DropDownList();
private string caption;
private Unit captionWidth;
private Unit captionPadding;
private bool rightAlignCaption;
private int month;
private int day;
private int year;
private bool autoPostBack;
private bool dateChangedEventRaised = false;
public event EventHandler DateChanged;
public OL_DateDDL()
{
ddlDay.SelectedIndexChange
ddlMonth.SelectedIndexChan
ddlYear.SelectedIndexChang
month = DateTime.Today.Month;
day = DateTime.Today.Day;
year = DateTime.Today.Year;
}
[Category("Appearance")]
[Description("The caption displayed to the left of the text box.")]
public string Caption
{
get { return caption; }
set { caption = value; }
}
[Category("Appearance")]
[Description("The width of the caption.")]
public Unit CaptionWidth
{
get { return captionWidth; }
set { captionWidth = value; }
}
[Category("Appearance")]
[Description("The space between the caption and the text box.")]
public Unit CaptionPadding
{
get { return captionPadding; }
set { captionPadding = value; }
}
[Category("Appearance")]
[Description("Determines if the caption is right-aligned.")]
public bool RightAlignCaption
{
get { return rightAlignCaption; }
set { rightAlignCaption = value; }
}
public DateTime Date
{
get
{
DateTime date;
// Attempt to parse the date
if (!DateTime.TryParse(this.M
{
// Invalid date! return MinValue
date = DateTime.MinValue;
}
return date;
}
set
{
this.Month = value.Month;
this.Day = value.Day;
this.Year = value.Year;
}
}
// Add this to the DateDDL class somewhere
protected virtual void OnDateChanged(EventArgs e)
{
// Trigger the event if it's defined,
// and we haven't triggered it already.
if (!dateChangedEventRaised && DateChanged != null)
{
DateChanged(this, e);
dateChangedEventRaised = true; // Don't trigger more than once.
}
}
// Change the property definitions in DateDDL as follows:
[Category("Misc"), Description("Gets or set the month.")]
public int Month
{
get
{
month = ddlMonth.SelectedIndex + 1;
return month;
}
set
{
month = value;
ddlMonth.SelectedIndex = month - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the day.")]
public int Day
{
get
{
day = ddlDay.SelectedIndex + 1;
return day;
}
set
{
day = value;
ddlDay.SelectedIndex = day - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the year.")]
public int Year
{
get
{
year = Convert.ToInt32(ddlYear.Se
return year;
}
set
{
year = value;
ddlYear.SelectedValue = year.ToString();
OnDateChanged(new EventArgs());
}
}
[Category("Misc")]
[Description("Determines whether a postback occurs "
+ "when the selection is changed.")]
[DefaultValue(false)]
public bool AutoPostBack
{
get { return autoPostBack; }
set { autoPostBack = value; }
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
protected override void CreateChildControls()
{
this.MakeCaption();
this.MakeCaptionPadding();
this.MakeMonthList();
this.MakeDayList();
this.MakeYearList();
Controls.Clear();
Controls.Add(lblCaption);
Controls.Add(lblCaptionPad
Controls.Add(ddlMonth);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlDay);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlYear);
// Register client script:
ddlMonth.Attributes.Add("o
ddlDay.Attributes.Add("onc
ddlYear.Attributes.Add("on
}
private void MakeCaption()
{
lblCaption.Text = Caption;
lblCaption.Width = CaptionWidth;
if (RightAlignCaption)
lblCaption.Style["text-ali
}
private void MakeCaptionPadding()
{
lblCaptionPadding.Width = CaptionPadding;
}
private void MakeMonthList()
{
ddlMonth.Width = Unit.Pixel(85);
ddlMonth.Items.Clear();
ddlMonth.Items.Add("Januar
ddlMonth.Items.Add("Februa
ddlMonth.Items.Add("March"
ddlMonth.Items.Add("April"
ddlMonth.Items.Add("May");
ddlMonth.Items.Add("June")
ddlMonth.Items.Add("July")
ddlMonth.Items.Add("August
ddlMonth.Items.Add("Septem
ddlMonth.Items.Add("Octobe
ddlMonth.Items.Add("Novemb
ddlMonth.Items.Add("Decemb
ddlMonth.AutoPostBack = AutoPostBack;
ddlMonth.SelectedIndex = Month - 1;
}
private void MakeDayList()
{
ddlDay.Width = Unit.Pixel(40);
ddlDay.Items.Clear();
for (int i = 1; i <= 31; i++)
ddlDay.Items.Add(i.ToStrin
ddlDay.SelectedValue = Day.ToString();
ddlDay.AutoPostBack = AutoPostBack;
}
private void MakeYearList()
{
ddlYear.Width = Unit.Pixel(65);
ddlYear.Items.Clear();
for (int i = DateTime.Today.Year - 100;
i <= DateTime.Today.Year - 18; i++)
ddlYear.Items.Add(i.ToStri
ddlYear.SelectedValue = Year.ToString();
ddlYear.AutoPostBack = AutoPostBack;
}
private void ddlMonth_SelectedIndexChan
{
this.Month = ddlMonth.SelectedIndex + 1;
this.AdjustDay();
}
private void ddlDay_SelectedIndexChange
{
this.Day = Convert.ToInt32(ddlDay.Sel
this.AdjustDay();
}
private void ddlYear_SelectedIndexChang
{
this.Year = Convert.ToInt32(ddlYear.Se
this.AdjustDay();
}
// C# Code behind in DateDDL class:
private void AdjustDay()
{
switch (Month)
{
case 4:
case 6:
case 9:
case 11:
if (Day > 30) Day = 30;
break;
case 2:
int yy = Year;
if (Day > 28)
Day = (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) ? 29 : 28;
break;
}
}
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Globalization;
using System.Web;
using System.Web.Profile;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Resources;
using log4net;
using System.Collections.Generic;
using DateDLL;
namespace OmegaLove.Web.UI
{
public partial class uxRegister : System.Web.UI.UserControl
{
// For generating random numbers.
private readonly Random random = new Random();
private static readonly ILog log = LogManager.GetLogger(typeof(uxRegister));
private String iUserID;
protected void Page_Load(object sender, EventArgs e)
{
//txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString() : "";
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.SelectedValue = "CA";
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.SelectedValue + ".gif";
// Create a random code and store it in the Session object.
Session["CaptchaImageText"] = GenerateRandomCode();
}
}
protected void DateDDL_DateChanged(object sender, EventArgs e)
{
var dateObj = (DateDDL)sender;
DateTime dateValue = dateObj.Date;
}
protected void imgRegister_Click(object sender, EventArgs e)
{
if ((CaptchaTextBox.Text == Session["CaptchaImageText"].ToString()) && Page.IsValid)
{
try
{
MembershipCreateStatus status;
MembershipUser user = Membership.CreateUser(txtUserName.Text, txtPassword.Text, txtMailFrom.Text, null, null, false, null, out status);
if (MembershipCreateStatus.Success == status)
{
var profile = new WebProfile().GetProfile(user.UserName);
Guid userId = (Guid)user.ProviderUserKey;
profile.Personal.UserName = txtUserName.Text;
profile.Personal.Password = txtPassword.Text;
profile.Personal.Email = txtMailFrom.Text;
profile.Personal.FirstName = txtFirstName.Text;
profile.Personal.LastName = txtLastName.Text;
profile.Personal.DOB = Convert.ToDateTime(DateDDL.Date, CultureInfo.InvariantCulture);
profile.Personal.Age = getAge(DateDDL.Date);
profile.Personal.Gender = ddlGender.SelectedValue;
profile.Personal.Seeking = ddlSeeking.SelectedValue;
profile.Personal.ConfirmationGUID = Guid.NewGuid().ToString("N");
profile.Personal.UserIP = Request.UserHostAddress;
profile.Personal.SessionID = Session.SessionID;
profile.Address.Country = ddlCountryRegister.SelectedValue;
profile.Address.Region = ddlRegion.SelectedValue;
profile.Address.City = ddlCity.SelectedValue;
profile.Address.ZipCode = txtZipCode.Text;
profile.Save();
WebMsgBox.Show("User created successfully!");
iUserID = txtUserName.Text;
string sData = ResourceEmail.NewMemberEmail;
sData = sData.Replace("[Name]", txtFirstName.Text.Trim());
sData = sData.Replace("[LINK]", "http://www.omegalove.com/Activate.aspx?ID=" + userId);
sData = sData.Replace("[UserName]", txtUserName.Text.Trim());
sData = sData.Replace("[Pwd]", txtPassword.Text.Trim());
SMTPManager.SendEmail("webmaster@omegalove.com", "OmegaLove", txtMailFrom.Text.Trim(),
sData, "New Member Activation", false);
Session["UserID"] = iUserID;
Response.Redirect("Registered.aspx");
}
What ragi0017 said above is correct.
This is my addition to it.
You have something like this in your code:
var dateObj = (DateDDL)sender;
DateTime dateValue = dateObj.Date;
so what you can do is define a public variable or property in your .aspx code behind. then set this value as you are doing in the above two lines.
Than you can assign that value to profile.Personal.DOB.
So e.g. declare DateTime dateValue outside to make it publicly avaialble within the class uxRegister. Assign it the value from your DDL and use it anywhere in the class.
This is my addition to it.
You have something like this in your code:
var dateObj = (DateDDL)sender;
DateTime dateValue = dateObj.Date;
so what you can do is define a public variable or property in your .aspx code behind. then set this value as you are doing in the above two lines.
Than you can assign that value to profile.Personal.DOB.
So e.g. declare DateTime dateValue outside to make it publicly avaialble within the class uxRegister. Assign it the value from your DDL and use it anywhere in the class.
ASKER
Guru, I have this : I declared it private in the behind code.
namespace OmegaLove.Web.UI
{
public partial class uxRegister : System.Web.UI.UserControl
{
// For generating random numbers.
private readonly Random random = new Random();
private static readonly ILog log = LogManager.GetLogger(typeo f(uxRegist er));
private String iUserID;
private DateTime dateValue;
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString () : "";
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.Selecte dValue = "CA";
dateValue.Date = ?
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.Selecte dValue + ".gif";
// Create a random code and store it in the Session object.
Session["CaptchaImageText" ] = GenerateRandomCode();
}
}
namespace OmegaLove.Web.UI
{
public partial class uxRegister : System.Web.UI.UserControl
{
// For generating random numbers.
private readonly Random random = new Random();
private static readonly ILog log = LogManager.GetLogger(typeo
private String iUserID;
private DateTime dateValue;
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.Selecte
dateValue.Date = ?
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.Selecte
// Create a random code and store it in the Session object.
Session["CaptchaImageText"
}
}
ASKER
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString () : "";
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.Selecte dValue = "CA";
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.Selecte dValue + ".gif";
// Create a random code and store it in the Session object.
Session["CaptchaImageText" ] = GenerateRandomCode();
}
}
dateObj = new DateDDL();
?
{
txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.Selecte
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.Selecte
// Create a random code and store it in the Session object.
Session["CaptchaImageText"
}
}
dateObj = new DateDDL();
?
ASKER
Is there something I am doing wrong:
public partial class uxRegister : System.Web.UI.UserControl
{
// For generating random numbers.
private readonly Random random = new Random();
private static readonly ILog log = LogManager.GetLogger(typeo f(uxRegist er));
private String iUserID;
protected OL_DateDLL.DateDDL dateObj;
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString () : "";
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.Selecte dValue = "CA";
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.Selecte dValue + ".gif";
dateObj = new DateDDL();
// Create a random code and store it in the Session object.
Session["CaptchaImageText" ] = GenerateRandomCode();
}
}
protected void DateDDL_DateChanged(object sender, EventArgs e)
{
dateObj = (DateDDL)sender;
DateTime dateValue = dateObj.Date;
}
protected void imgRegister_Click(object sender, EventArgs e)
{
if ((CaptchaTextBox.Text == Session["CaptchaImageText" ].ToString ()) && Page.IsValid)
{
try
{
MembershipCreateStatus status;
MembershipUser user = Membership.CreateUser(txtU serName.Te xt, txtPassword.Text, txtMailFrom.Text, null, null, false, null, out status);
if (MembershipCreateStatus.Su ccess == status)
{
var profile = new WebProfile().GetProfile(us er.UserNam e);
DateTime dateValue = dateObj.Date;
Guid userId = (Guid)user.ProviderUserKey ;
profile.Personal.UserName = txtUserName.Text;
profile.Personal.Password = txtPassword.Text;
profile.Personal.Email = txtMailFrom.Text;
profile.Personal.FirstName = txtFirstName.Text;
profile.Personal.LastName = txtLastName.Text;
profile.Personal.DOB = Convert.ToDateTime(dateObj .Date, CultureInfo.InvariantCultu re);
profile.Personal.Age = getAge(dateObj.Date);
profile.Personal.Gender = ddlGender.SelectedValue;
profile.Personal.Seeking = ddlSeeking.SelectedValue;
profile.Personal.Confirmat ionGUID = Guid.NewGuid().ToString("N ");
profile.Personal.UserIP = Request.UserHostAddress;
profile.Personal.SessionID = Session.SessionID;
profile.Address.Country = ddlCountryRegister.Selecte dValue;
profile.Address.Region = ddlRegion.SelectedValue;
profile.Address.City = ddlCity.SelectedValue;
profile.Address.ZipCode = txtZipCode.Text;
profile.Save();
WebMsgBox.Show("User created successfully!");
iUserID = txtUserName.Text;
string sData = ResourceEmail.NewMemberEma il;
sData = sData.Replace("[Name]", txtFirstName.Text.Trim());
sData = sData.Replace("[LINK]", "http://www.omegalove.com/Activate.aspx?ID=" + userId);
sData = sData.Replace("[UserName]" , txtUserName.Text.Trim());
sData = sData.Replace("[Pwd]", txtPassword.Text.Trim());
SMTPManager.SendEmail("web master@ome galove.com ", "OmegaLove", txtMailFrom.Text.Trim(),
sData, "New Member Activation", false);
Session["UserID"] = iUserID;
Response.Redirect("Registe red.aspx") ;
}
else
{
// first else block:
switch (status)
{
case MembershipCreateStatus.Dup licateUser Name:
WebMsgBox.Show("There already exists a user with this username.");
break;
case MembershipCreateStatus.Dup licateEmai l:
WebMsgBox.Show("There already exists a user with this email address.");
break;
case MembershipCreateStatus.Dup licateProv iderUserKe y:
case MembershipCreateStatus.Inv alidAnswer :
case MembershipCreateStatus.Inv alidEmail:
case MembershipCreateStatus.Inv alidProvid erUserKey:
case MembershipCreateStatus.Inv alidQuesti on:
case MembershipCreateStatus.Inv alidUserNa me:
WebMsgBox.Show(string.Form at("The {0} provided was invalid.", status.ToString().Substrin g(7)));
break;
default:
WebMsgBox.Show("There was an unknown error; the user account was NOT created.");
break;
}
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message) ;
}
}
else
{
WebMsgBox.Show("Invalid Access Code, try again.");
CaptchaTextBox.Text = "";
Session["CaptchaImageText" ] = GenerateRandomCode();
}
}
Is this what u meant?
Please check this.
public partial class uxRegister : System.Web.UI.UserControl
{
// For generating random numbers.
private readonly Random random = new Random();
private static readonly ILog log = LogManager.GetLogger(typeo
private String iUserID;
protected OL_DateDLL.DateDDL dateObj;
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Focus();
String UserID = Session["UserID"] != null ? Session["UserID"].ToString
if (!Page.IsPostBack)
{
BindDropDownList();
cddCountryRegister.Selecte
imgFlagRegister.ImageUrl = "~/images/flags/" + cddCountryRegister.Selecte
dateObj = new DateDDL();
// Create a random code and store it in the Session object.
Session["CaptchaImageText"
}
}
protected void DateDDL_DateChanged(object
{
dateObj = (DateDDL)sender;
DateTime dateValue = dateObj.Date;
}
protected void imgRegister_Click(object sender, EventArgs e)
{
if ((CaptchaTextBox.Text == Session["CaptchaImageText"
{
try
{
MembershipCreateStatus status;
MembershipUser user = Membership.CreateUser(txtU
if (MembershipCreateStatus.Su
{
var profile = new WebProfile().GetProfile(us
DateTime dateValue = dateObj.Date;
Guid userId = (Guid)user.ProviderUserKey
profile.Personal.UserName = txtUserName.Text;
profile.Personal.Password = txtPassword.Text;
profile.Personal.Email = txtMailFrom.Text;
profile.Personal.FirstName
profile.Personal.LastName = txtLastName.Text;
profile.Personal.DOB = Convert.ToDateTime(dateObj
profile.Personal.Age = getAge(dateObj.Date);
profile.Personal.Gender = ddlGender.SelectedValue;
profile.Personal.Seeking = ddlSeeking.SelectedValue;
profile.Personal.Confirmat
profile.Personal.UserIP = Request.UserHostAddress;
profile.Personal.SessionID
profile.Address.Country = ddlCountryRegister.Selecte
profile.Address.Region = ddlRegion.SelectedValue;
profile.Address.City = ddlCity.SelectedValue;
profile.Address.ZipCode = txtZipCode.Text;
profile.Save();
WebMsgBox.Show("User created successfully!");
iUserID = txtUserName.Text;
string sData = ResourceEmail.NewMemberEma
sData = sData.Replace("[Name]", txtFirstName.Text.Trim());
sData = sData.Replace("[LINK]", "http://www.omegalove.com/Activate.aspx?ID=" + userId);
sData = sData.Replace("[UserName]"
sData = sData.Replace("[Pwd]", txtPassword.Text.Trim());
SMTPManager.SendEmail("web
sData, "New Member Activation", false);
Session["UserID"] = iUserID;
Response.Redirect("Registe
}
else
{
// first else block:
switch (status)
{
case MembershipCreateStatus.Dup
WebMsgBox.Show("There already exists a user with this username.");
break;
case MembershipCreateStatus.Dup
WebMsgBox.Show("There already exists a user with this email address.");
break;
case MembershipCreateStatus.Dup
case MembershipCreateStatus.Inv
case MembershipCreateStatus.Inv
case MembershipCreateStatus.Inv
case MembershipCreateStatus.Inv
case MembershipCreateStatus.Inv
WebMsgBox.Show(string.Form
break;
default:
WebMsgBox.Show("There was an unknown error; the user account was NOT created.");
break;
}
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message)
}
}
else
{
WebMsgBox.Show("Invalid Access Code, try again.");
CaptchaTextBox.Text = "";
Session["CaptchaImageText"
}
}
Is this what u meant?
Please check this.
you are getting error at the following line
profile.Personal.DOB = Convert.ToDateTime(DateDDL .Date, CultureInfo.InvariantCultu re);
because you are trying to access an instance property Date directly from the class and its not an issue if you use
dateObj = new DateDDL();
dateValue.Date = ?
profile.Personal.DOB = Convert.ToDateTime(DateDDL
because you are trying to access an instance property Date directly from the class and its not an issue if you use
dateObj = new DateDDL();
dateValue.Date = ?
ASKER
I get an error on
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'OL_DateDLL:OL_DateDLL'.
Source Error:
Line 233:
Line 234: <td class="physicalLightBox">& nbsp;
Line 235: <OL_DateDLL:OL_DateDLL ID="OL_DateDLL1" runat="server"
Line 236: ondatechanged="DateDDL_Dat eChanged" Font-Bold="True" />
Line 237: </td>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uxRegister.asc x.cs" Inherits="OmegaLove.Web.UI .uxRegiste r" %>
<%@ Register Assembly="OL_DateDLL" Namespace="OL_DateDLL" TagPrefix="OL_DateDLL" %>
<%@ Register Assembly="ClassLibrary" Namespace="ClassLibrary" TagPrefix="cc3"%>
<%@ Register Assembly="AjaxControlToolk it" Namespace="AjaxControlTool kit" TagPrefix="ajaxToolkit" %>
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'OL_DateDLL:OL_DateDLL'.
Source Error:
Line 233:
Line 234: <td class="physicalLightBox">&
Line 235: <OL_DateDLL:OL_DateDLL ID="OL_DateDLL1" runat="server"
Line 236: ondatechanged="DateDDL_Dat
Line 237: </td>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uxRegister.asc
<%@ Register Assembly="OL_DateDLL" Namespace="OL_DateDLL" TagPrefix="OL_DateDLL" %>
<%@ Register Assembly="ClassLibrary" Namespace="ClassLibrary" TagPrefix="cc3"%>
<%@ Register Assembly="AjaxControlToolk
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OL_DateDLL
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:OL_DateDDL runat=server></{0}:DateDDL>")]
public class OL_DateDDL : CompositeControl
{
private Label lblCaption = new Label();
private Label lblCaptionPadding = new Label();
private DropDownList ddlMonth = new DropDownList();
private DropDownList ddlDay = new DropDownList();
private DropDownList ddlYear = new DropDownList();
private string caption;
private Unit captionWidth;
private Unit captionPadding;
private bool rightAlignCaption;
private int month;
private int day;
private int year;
private bool autoPostBack;
private bool dateChangedEventRaised = false;
public event EventHandler DateChanged;
public OL_DateDDL()
{
ddlDay.SelectedIndexChanged += new EventHandler(ddlDay_SelectedIndexChanged);
ddlMonth.SelectedIndexChanged += new EventHandler(ddlMonth_SelectedIndexChanged);
ddlYear.SelectedIndexChanged += new EventHandler(ddlYear_SelectedIndexChanged);
month = DateTime.Today.Month;
day = DateTime.Today.Day;
year = DateTime.Today.Year;
}
[Category("Appearance")]
[Description("The caption displayed to the left of the text box.")]
public string Caption
{
get { return caption; }
set { caption = value; }
}
[Category("Appearance")]
[Description("The width of the caption.")]
public Unit CaptionWidth
{
get { return captionWidth; }
set { captionWidth = value; }
}
[Category("Appearance")]
[Description("The space between the caption and the text box.")]
public Unit CaptionPadding
{
get { return captionPadding; }
set { captionPadding = value; }
}
[Category("Appearance")]
[Description("Determines if the caption is right-aligned.")]
public bool RightAlignCaption
{
get { return rightAlignCaption; }
set { rightAlignCaption = value; }
}
public DateTime Date
{
get
{
DateTime date;
// Attempt to parse the date
if (!DateTime.TryParse(this.Month + "/" + this.Day + "/" + this.Year, out date))
{
// Invalid date! return MinValue
date = DateTime.MinValue;
}
return date;
}
set
{
this.Month = value.Month;
this.Day = value.Day;
this.Year = value.Year;
}
}
// Add this to the DateDDL class somewhere
protected virtual void OnDateChanged(EventArgs e)
{
// Trigger the event if it's defined,
// and we haven't triggered it already.
if (!dateChangedEventRaised && DateChanged != null)
{
DateChanged(this, e);
dateChangedEventRaised = true; // Don't trigger more than once.
}
}
// Change the property definitions in DateDDL as follows:
[Category("Misc"), Description("Gets or set the month.")]
public int Month
{
get
{
month = ddlMonth.SelectedIndex + 1;
return month;
}
set
{
month = value;
ddlMonth.SelectedIndex = month - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the day.")]
public int Day
{
get
{
day = ddlDay.SelectedIndex + 1;
return day;
}
set
{
day = value;
ddlDay.SelectedIndex = day - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the year.")]
public int Year
{
get
{
year = Convert.ToInt32(ddlYear.SelectedValue);
return year;
}
set
{
year = value;
ddlYear.SelectedValue = year.ToString();
OnDateChanged(new EventArgs());
}
}
[Category("Misc")]
[Description("Determines whether a postback occurs "
+ "when the selection is changed.")]
[DefaultValue(false)]
public bool AutoPostBack
{
get { return autoPostBack; }
set { autoPostBack = value; }
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
protected override void CreateChildControls()
{
this.MakeCaption();
this.MakeCaptionPadding();
this.MakeMonthList();
this.MakeDayList();
this.MakeYearList();
Controls.Clear();
Controls.Add(lblCaption);
Controls.Add(lblCaptionPadding);
Controls.Add(ddlMonth);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlDay);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlYear);
// Register client script:
ddlMonth.Attributes.Add("onchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
ddlDay.Attributes.Add("onchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
ddlYear.Attributes.Add("onchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
}
private void MakeCaption()
{
lblCaption.Text = Caption;
lblCaption.Width = CaptionWidth;
if (RightAlignCaption)
lblCaption.Style["text-align"] = "right";
}
private void MakeCaptionPadding()
{
lblCaptionPadding.Width = CaptionPadding;
}
private void MakeMonthList()
{
ddlMonth.Width = Unit.Pixel(85);
ddlMonth.Items.Clear();
ddlMonth.Items.Add("January");
ddlMonth.Items.Add("February");
ddlMonth.Items.Add("March");
ddlMonth.Items.Add("April");
ddlMonth.Items.Add("May");
ddlMonth.Items.Add("June");
ddlMonth.Items.Add("July");
ddlMonth.Items.Add("August");
ddlMonth.Items.Add("September");
ddlMonth.Items.Add("October");
ddlMonth.Items.Add("November");
ddlMonth.Items.Add("December");
ddlMonth.AutoPostBack = AutoPostBack;
ddlMonth.SelectedIndex = Month - 1;
}
private void MakeDayList()
{
ddlDay.Width = Unit.Pixel(40);
ddlDay.Items.Clear();
for (int i = 1; i <= 31; i++)
ddlDay.Items.Add(i.ToString());
ddlDay.SelectedValue = Day.ToString();
ddlDay.AutoPostBack = AutoPostBack;
}
private void MakeYearList()
{
ddlYear.Width = Unit.Pixel(65);
ddlYear.Items.Clear();
for (int i = DateTime.Today.Year - 100;
i <= DateTime.Today.Year - 18; i++)
ddlYear.Items.Add(i.ToString());
ddlYear.SelectedValue = Year.ToString();
ddlYear.AutoPostBack = AutoPostBack;
}
private void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
this.Month = ddlMonth.SelectedIndex + 1;
this.AdjustDay();
}
private void ddlDay_SelectedIndexChanged(object sender, EventArgs e)
{
this.Day = Convert.ToInt32(ddlDay.SelectedValue);
this.AdjustDay();
}
private void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
this.Year = Convert.ToInt32(ddlYear.SelectedValue);
this.AdjustDay();
}
// C# Code behind in DateDDL class:
private void AdjustDay()
{
switch (Month)
{
case 4:
case 6:
case 9:
case 11:
if (Day > 30) Day = 30;
break;
case 2:
int yy = Year;
if (Day > 28)
Day = (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) ? 29 : 28;
break;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
First one tells me that the it does not see the server tag.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'OL_DateDLL:OL_DateDLL'.
Source Error:
Line 233:
Line 234: <td class="physicalLightBox">& nbsp;
Line 235: <OL_DateDLL:OL_DateDLL ID="OL
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'OL_DateDLL:OL_DateDLL'.
Source Error:
Line 233:
Line 234: <td class="physicalLightBox">&
Line 235: <OL_DateDLL:OL_DateDLL ID="OL
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OL_DateDLL
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:OL_DateDDL runat=server></{0}:DateDDL>")]
public class OL_DateDDL : CompositeControl
{
private Label lblCaption = new Label();
private Label lblCaptionPadding = new Label();
private DropDownList ddlMonth = new DropDownList();
private DropDownList ddlDay = new DropDownList();
private DropDownList ddlYear = new DropDownList();
private string caption;
private Unit captionWidth;
private Unit captionPadding;
private bool rightAlignCaption;
private int month;
private int day;
private int year;
private bool autoPostBack;
private bool dateChangedEventRaised = false;
public event EventHandler DateChanged;
public OL_DateDDL()
{
ddlDay.SelectedIndexChanged += new EventHandler(ddlDay_SelectedIndexChanged);
ddlMonth.SelectedIndexChanged += new EventHandler(ddlMonth_SelectedIndexChanged);
ddlYear.SelectedIndexChanged += new EventHandler(ddlYear_SelectedIndexChanged);
month = DateTime.Today.Month;
day = DateTime.Today.Day;
year = DateTime.Today.Year;
}
[Category("Appearance")]
[Description("The caption displayed to the left of the text box.")]
public string Caption
{
get { return caption; }
set { caption = value; }
}
[Category("Appearance")]
[Description("The width of the caption.")]
public Unit CaptionWidth
{
get { return captionWidth; }
set { captionWidth = value; }
}
[Category("Appearance")]
[Description("The space between the caption and the text box.")]
public Unit CaptionPadding
{
get { return captionPadding; }
set { captionPadding = value; }
}
[Category("Appearance")]
[Description("Determines if the caption is right-aligned.")]
public bool RightAlignCaption
{
get { return rightAlignCaption; }
set { rightAlignCaption = value; }
}
public DateTime Date
{
get
{
DateTime date;
// Attempt to parse the date
if (!DateTime.TryParse(this.Month + "/" + this.Day + "/" + this.Year, out date))
{
// Invalid date! return MinValue
date = DateTime.MinValue;
}
return date;
}
set
{
this.Month = value.Month;
this.Day = value.Day;
this.Year = value.Year;
}
}
// Add this to the DateDDL class somewhere
protected virtual void OnDateChanged(EventArgs e)
{
// Trigger the event if it's defined,
// and we haven't triggered it already.
if (!dateChangedEventRaised && DateChanged != null)
{
DateChanged(this, e);
dateChangedEventRaised = true; // Don't trigger more than once.
}
}
// Change the property definitions in DateDDL as follows:
[Category("Misc"), Description("Gets or set the month.")]
public int Month
{
get
{
month = ddlMonth.SelectedIndex + 1;
return month;
}
set
{
month = value;
ddlMonth.SelectedIndex = month - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the day.")]
public int Day
{
get
{
day = ddlDay.SelectedIndex + 1;
return day;
}
set
{
day = value;
ddlDay.SelectedIndex = day - 1;
OnDateChanged(new EventArgs());
}
}
[Category("Misc"), Description("Gets or sets the year.")]
public int Year
{
get
{
year = Convert.ToInt32(ddlYear.SelectedValue);
return year;
}
set
{
year = value;
ddlYear.SelectedValue = year.ToString();
OnDateChanged(new EventArgs());
}
}
[Category("Misc")]
[Description("Determines whether a postback occurs "
+ "when the selection is changed.")]
[DefaultValue(false)]
public bool AutoPostBack
{
get { return autoPostBack; }
set { autoPostBack = value; }
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
protected override void CreateChildControls()
{
this.MakeCaption();
this.MakeCaptionPadding();
this.MakeMonthList();
this.MakeDayList();
this.MakeYearList();
Controls.Clear();
Controls.Add(lblCaption);
Controls.Add(lblCaptionPadding);
Controls.Add(ddlMonth);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlDay);
Controls.Add(new LiteralControl(" "));
Controls.Add(ddlYear);
// Register client script:
ddlMonth.Attributes.Add("onchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
ddlDay.Attributes.Add("onchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
ddlYear.Attributes.Add("onchange", "adjustDay('" + ddlMonth.ClientID + "','" + ddlDay.ClientID + "','" + ddlYear.ClientID + "');");
}
private void MakeCaption()
{
lblCaption.Text = Caption;
lblCaption.Width = CaptionWidth;
if (RightAlignCaption)
lblCaption.Style["text-align"] = "right";
}
private void MakeCaptionPadding()
{
lblCaptionPadding.Width = CaptionPadding;
}
private void MakeMonthList()
{
ddlMonth.Width = Unit.Pixel(85);
ddlMonth.Items.Clear();
ddlMonth.Items.Add("January");
ddlMonth.Items.Add("February");
ddlMonth.Items.Add("March");
ddlMonth.Items.Add("April");
ddlMonth.Items.Add("May");
ddlMonth.Items.Add("June");
ddlMonth.Items.Add("July");
ddlMonth.Items.Add("August");
ddlMonth.Items.Add("September");
ddlMonth.Items.Add("October");
ddlMonth.Items.Add("November");
ddlMonth.Items.Add("December");
ddlMonth.AutoPostBack = AutoPostBack;
ddlMonth.SelectedIndex = Month - 1;
}
private void MakeDayList()
{
ddlDay.Width = Unit.Pixel(40);
ddlDay.Items.Clear();
for (int i = 1; i <= 31; i++)
ddlDay.Items.Add(i.ToString());
ddlDay.SelectedValue = Day.ToString();
ddlDay.AutoPostBack = AutoPostBack;
}
private void MakeYearList()
{
ddlYear.Width = Unit.Pixel(65);
ddlYear.Items.Clear();
for (int i = DateTime.Today.Year - 100;
i <= DateTime.Today.Year - 18; i++)
ddlYear.Items.Add(i.ToString());
ddlYear.SelectedValue = Year.ToString();
ddlYear.AutoPostBack = AutoPostBack;
}
private void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
this.Month = ddlMonth.SelectedIndex + 1;
this.AdjustDay();
}
private void ddlDay_SelectedIndexChanged(object sender, EventArgs e)
{
this.Day = Convert.ToInt32(ddlDay.SelectedValue);
this.AdjustDay();
}
private void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
this.Year = Convert.ToInt32(ddlYear.SelectedValue);
this.AdjustDay();
}
// C# Code behind in DateDDL class:
private void AdjustDay()
{
switch (Month)
{
case 4:
case 6:
case 9:
case 11:
if (Day > 30) Day = 30;
break;
case 2:
int yy = Year;
if (Day > 28)
Day = (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) ? 29 : 28;
break;
}
}
}
}
you have to create an instance of the class and then only use it
profile.Personal.DOB = Convert.ToDateTime(DateDDL