Solved

mermbership registration failing on datepicker.

Posted on 2008-10-24
4
215 Views
Last Modified: 2012-05-05
I have the following is failing

 MembershipUser user = Membership.CreateUser(txtUserName.Text, txtPassword.Text, txtEmail.Text);

                ProfileCommon pc = Profile.GetProfile(user.UserName);
                pc.Email = txtEmail.Text;
                pc.FullName = txtFullName.Text;
                pc.DOB = DateTime.Parse(Datepicker.Selected_Date);
                pc.Gender = Gender.ToString();

                pc.City = ddlCity.SelectedValue;
                pc.Region = ddlRegion.SelectedValue;
                pc.Country = ddlCountryRegister.SelectedValue;
                pc.Save();

 <membership defaultProvider="OL_MembershipProvider" userIsOnlineTimeWindow="15">
      <providers>
        <add name="OL_MembershipProvider" connectionStringName="LocalSqlServer" applicationName="/" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Encrypted" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
    </membership>
    <profile defaultProvider="OL_ProfileProvider">
      <providers>
        <add name="OL_ProfileProvider" connectionStringName="LocalSqlServer" type="System.Web.Profile.SqlProfileProvider"/>
      </providers>
      <properties>
        <add name="Email"/>
        <add name="UserName"/>
        <add name="Password"/>
        <add name="FullName"/>
        <add name="Gender"/>
        <add name="DOB" type="System.DateTime"/>
        <add name="City"/>
        <add name="Region"/>
        <add name="Country"/>
      </properties>
    </profile>

Server Error in '/OL_Web' Application.
--------------------------------------------------------------------------------

String was not recognized as a valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[FormatException: String was not recognized as a valid DateTime.]
   System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +2834318
   mm_date.datepicker.LoadPostData(String postDataKey, NameValueCollection values) +124
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +346
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743

 
where do i need to make sure the dob be defined in the membershiptable.
if (!Page.IsPostBack)

            {

                this.Datepicker.Selected_Date = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToLower();

}

Open in new window

0
Comment
Question by:mathieu_cupryk
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
RishadanPort earned 500 total points
Comment Utility
Can you please show is this property in code:

Datepicker.Selected_Date
0
 

Author Comment

by:mathieu_cupryk
Comment Utility
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Collections.Specialized;
using System.Text;

namespace mm_date
{
      /// <summary>
      /// DatePicker - Generates drop down select objects for date selection
      /// Client side javascript ensures only valid date returned.
      /// </summary>

      [DefaultProperty("Text"),
            ToolboxData("<{0}:datepicker runat=server></{0}:datepicker>")]

      public class datepicker : System.Web.UI.WebControls.WebControl, System.Web.UI.IPostBackDataHandler
      {
            //Declarations
        private int begyear = System.DateTime.Today.Year - 18;
            private int endyear = System.DateTime.Today.Year - 100;
            private int date_mode = 1;
            private int form_level = 0;
            private DateTime initial_date = System.DateTime.Today;
            private int sel_month = System.DateTime.Today.Month;
            private int sel_day = System.DateTime.Today.Day;
            private int sel_year = System.DateTime.Today.Year;
            private int picked_month = 0;
            private int picked_day = 0;
            private int picked_year = 0;
            private string selected_date;
            private string sel_date_convert;
            private DateTime date_picked;
            private string control="Datepicker";

            //Define Properties

            //Control Release & About
            [Bindable(false),
            Category("About"),
            DefaultValue(""),
            Description("Control:  Datepicker\n" +
                  "Version:  Ver 1.01 - 12/01/2003\n" +
                  "Author:   Michael McLain\n" +
                  "Desc:      Date dropdown selection control\n")]

            public string Control
            {
                  get
                  {
                        return control;
                  }
                  set
                  {
                        control = value;
                  }
            }


            //Posted Date Returned
            [Bindable(true),
            Category("Returned Values"),
            DefaultValue(""),
            Description("Returned date selected (string)")]
            public string Selected_Date
            {
                  get
                  {
                        return selected_date;
                  }
                  set
                  {
                        selected_date = value;
                  }
            }

            public bool LoadPostData(String postDataKey, NameValueCollection values)
            {
                  selected_date =      values[this.UniqueID.ToString()];
                  sel_date_convert = values[this.UniqueID.ToString()+ "_conv"];
                  date_picked = System.DateTime.Parse(sel_date_convert).Date;
                  Month = date_picked.Month;
                  Day = date_picked.Day;
                  Year = date_picked.Year;
                  if (this.EnableViewState)
                  {
                        this.initial_date = date_picked;
                  }
                  return false;
            }

            public void RaisePostDataChangedEvent()
            {
            }

            //Returned date in datetime format
            [Bindable(true),
            Category("Returned Values"),
            DefaultValue(""),
            Description("Returned date selected (datetime)")]
            public DateTime Date_Picked
            {
                  get
                  {
                        return date_picked;
                  }
                  set
                  {
                        date_picked = value;
                  }
            }

            //Returned Month
            [Bindable(false),
            Category("Returned Values"),
            DefaultValue(""),
            Description("Returned month selected (int)")]
            public int Month
            {
                  get
                  {
                        return picked_month;
                  }
                  set
                  {
                        picked_month = value;
                  }
            }

            //Returned Day
            [Bindable(false),
            Category("Returned Values"),
            DefaultValue(""),
            Description("Returned day selected (int)")]
            public int Day
            {
                  get
                  {
                        return picked_day;
                  }
                  set
                  {
                        picked_day = value;
                  }
            }

            //Returned year
            [Bindable(false),
            Category("Returned Values"),
            DefaultValue(""),
            Description("Returned year selected (int)")]
            public int Year
            {
                  get
                  {
                        return picked_year;
                  }
                  set
                  {
                        picked_year = value;
                  }
            }
            
            //Begin Year
            [Bindable(true),
            Category("Setup Values"),
            DefaultValue(""),
            Description("Beginning Year Select Range")]
            public int YearRange_Start
            {
                  get
                  {
                        return begyear;
                  }

                  set
                  {
                        begyear = value;
                  }
            }

            //End Year
            [Bindable(true),
            Category("Setup Values"),
            DefaultValue(""),
            Description("Ending Year Select Range")]
            public int YearRange_End
            {
                  get
                  {
                        return endyear;
                  }

                  set
                  {
                        endyear = value;
                  }
            }

            //Initial date selected
            [Bindable(true),
            Category("Setup Values"),
            DefaultValue(""),
            Description("Initial selected date")]
            public DateTime Initial_Date
            {
                  get
                  {
                        return initial_date;
                  }

                  set
                  {
                        initial_date = value;
                  }
            }

            //Date format returned (in string format)
            //Included for backward compatibility to Classic ASP version
            [Bindable(true),
            Category("Setup Values"),
            DefaultValue(""),
            Description("Date format returned in (Selected_Date).\n1 - MM/DD/YYYY\n2 - DD/MM/YYYY\n3 - YYYYMMDD\n4 - universal format")]
            public int Date_Mode
            {
                  get
                  {
                        return date_mode;
                  }

                  set
                  {
                        date_mode = value;
                  }
            }

            //Form level index to allow handling multiple forms per page.
            [Bindable(false),
            Category("Setup Values"),
            DefaultValue(""),
            Description("Document form index level")]
            public int Form_Level
            {
                  get
                  {
                        return form_level;
                  }

                  set
                  {
                        form_level = value;
                  }
            }

            /// <summary>
            /// Render this control to the output parameter specified.
            /// </summary>
            /// <param name="output"> The HTML writer to write out to </param>
            protected override void Render(HtmlTextWriter output)
            {
                  string cid = this.UniqueID.ToString();
                  string isSelected = "";
            string docref = cid;
//                  string docref = "document.forms[" + this.form_level.ToString() + "]." + cid;
                  string onchg =  " onChange=\"tg_mm_setdays('" + docref + "'," + date_mode.ToString() + ")\"";
                  string objinit = "<script language=javascript>tg_mm_setdays('" + docref + "'," + date_mode.ToString() + ")</script>";

                  //Build control style
                  string ostyle = "";
                  string c_ostyle = "";
                  string ostylevalue = "";
                  int stylecount = this.Style.Count;
                  foreach (string stmp in this.Style.Keys)
                  {
                        ostylevalue = this.Style[stmp].ToString();
                        c_ostyle = c_ostyle + stmp + ": " + ostylevalue + "; ";
                  }

                  StringBuilder s = new StringBuilder();

                  //Set component container if applied style
                  //Container used to handle grid layout mode
                  if (c_ostyle != "" )
                  {
                        s.Append("<div style=\"" + c_ostyle + "\">");
                  }

                  //Build select drop down styles
                  string color = "";
                  if (!this.ForeColor.IsEmpty)
                  {
                        color = this.ForeColor.Name;
                        if (color != "")
                        {
                              if (!this.ForeColor.IsNamedColor && !this.ForeColor.IsSystemColor)
                              {
                                    color = "#" + color.Substring(2,6);
                              }
                        }
                  }
                  string backcolor = "";
                  if (!this.BackColor.IsEmpty)
                  {
                        backcolor = this.BackColor.Name;
                        if (backcolor != "")
                        {
                              if (!this.BackColor.IsNamedColor && !this.BackColor.IsSystemColor)
                              {
                                    backcolor = "#" + backcolor.Substring(2,6);
                              }
                        }
                  }
                  string fontname = this.Font.Name;
                  string fontsize = this.Font.Size.ToString();
                  string cssclass = this.CssClass;
                  bool fontstyle = this.Font.Italic;
                  bool fontbold = this.Font.Bold;
                  bool underline = this.Font.Underline;
                  bool overline = this.Font.Overline;
                  bool strikeout = this.Font.Strikeout;
                  string textdecoration = "";

//TEXT-DECORATION: underline overline line-through
                  if (underline || overline || strikeout)
                  {
                        textdecoration = "TEXT-DECORATION: ";
                        if (underline)
                        {
                              textdecoration = textdecoration + "underline ";
                        }
                        if (overline)
                        {
                              textdecoration = textdecoration + "overline ";
                        }
                        if (strikeout)
                        {
                              textdecoration = textdecoration + "strikeout ";
                        }
                        textdecoration = textdecoration + ";";
                  }

                  if (cssclass != "")
                  {
                        cssclass = " class=\"" + cssclass + "\"";
                  }
                  ostyle=" style=\"";
                  if (fontname != "")
                  {
                        ostyle = ostyle + "FONT-FAMILY: " + fontname + ";";
                  }
                  if (fontsize != "")
                  {
                        ostyle = ostyle + "FONT-SIZE: " + fontsize + ";";
                  }
                  if (fontstyle)
                  {
                        ostyle = ostyle + "FONT-STYLE: italic;";
                  }
                  if (fontbold)
                  {
                        ostyle = ostyle + "FONT-WEIGHT: bold;";
                  }

                  if (color !="")
                  {
                        ostyle = ostyle + "COLOR: " + color + ";";
                  }

                  if (backcolor !="")
                  {
                        ostyle = ostyle + "BACKGROUND-COLOR: " + backcolor + ";";
                  }

                  if (textdecoration !="")
                  {
                        ostyle = ostyle + textdecoration;
                  }
                  ostyle = ostyle + "\"" + cssclass;

                  //Build Month Dropdown
                  sel_month = initial_date.Month;
                  sel_day = initial_date.Day;
                  sel_year = initial_date.Year;
                  
                  //Determine days in Month
                  DateTime wrkdate = initial_date.Date;
                  int daysinmonth = 0;
                  while (sel_month == wrkdate.Month)
                  {
                        daysinmonth = wrkdate.Day;
                        wrkdate = wrkdate.AddDays(1);
                  }
                  s.Append("\n<select name=\"" + cid + "_month\"" + onchg + ostyle + ">\n");
                  isSelected = checkselected(1, sel_month);
                  s.Append("<option value=1" + isSelected + ">Jan</option>\n");
                  isSelected = checkselected(2, sel_month);
                  s.Append("<option value=2" + isSelected + ">Feb</option>\n");
                  isSelected = checkselected(3, sel_month);
                  s.Append("<option value=3" + isSelected + ">Mar</option>\n");
                  isSelected = checkselected(4, sel_month);
                  s.Append("<option value=4" + isSelected + ">Apr</option>\n");
                  isSelected = checkselected(5, sel_month);
                  s.Append("<option value=5" + isSelected + ">May</option>\n");
                  isSelected = checkselected(6, sel_month);
                  s.Append("<option value=6" + isSelected + ">Jun</option>\n");
                  isSelected = checkselected(7, sel_month);
                  s.Append("<option value=7" + isSelected + ">Jul</option>\n");
                  isSelected = checkselected(8, sel_month);
                  s.Append("<option value=8" + isSelected + ">Aug</option>\n");
                  isSelected = checkselected(9, sel_month);
                  s.Append("<option value=9" + isSelected + ">Sep</option>\n");
                  isSelected = checkselected(10, sel_month);
                  s.Append("<option value=10" + isSelected + ">Oct</option>\n");
                  isSelected = checkselected(11, sel_month);
                  s.Append("<option value=11" + isSelected + ">Nov</option>\n");
                  isSelected = checkselected(12, sel_month);
                  s.Append("<option value=12" + isSelected + ">Dec</option>\n");
                  s.Append("</select>\n");

                  //Build Day Dropdown
                  s.Append("\n<select name=\"" + cid + "_day\"" + onchg + ostyle + ">\n");
                  int i;
                  string lc_i;
                  for (i=1;i<daysinmonth+1;i++)
                  {
                        lc_i = i.ToString();
                        if (lc_i.Length == 1)
                        {
                              lc_i = "0" + lc_i;
                        }
                        isSelected = checkselected(i, sel_day);
                        s.Append("<option value=" + i.ToString() + isSelected + ">" + lc_i + "</option>\n");
                  }
                  s.Append("</select>\n");

                  //Build Year Dropdown
                  s.Append("\n<select name=\"" + cid + "_year\"" + onchg + ostyle + ">\n");
            //for (i=begyear; i<=endyear; i++)
            //{
            //    lc_i = i.ToString();
            //    isSelected = checkselected(i, sel_year);
            //    s.Append("<option value=" + i.ToString() + isSelected + ">" + i.ToString() + "</option>\n");
            //}
            for (i = endyear; i <= begyear; i++)
            {
                lc_i = i.ToString();
                isSelected = checkselected(i, sel_year);
                s.Append("<option value=" + i.ToString() + isSelected + ">" + i.ToString() + "</option>\n");
            }
                  s.Append("</select>\n");

                  //Build hidden input type to hold current date
                  s.Append("\n<input type=hidden name=\"" + cid + "\">\n");
                  s.Append("\n<input type=hidden name=\"" + cid + "_conv\">\n");

                  //Close container for applied styles
                  if (c_ostyle != "" )
                  {
                        s.Append("</div>");
                  }

                  //Add in object initialization for Netscape inline script bug
                  s.Append(objinit);

                  //Render control
                  output.Write(s.ToString());
            }

            protected string checkselected(int current_selection, int compair_selection)
            {
                  if (current_selection == compair_selection)
                  {
                        return " SELECTED";
                  }
                  return "";
            }

//            protected void Write_Client_Scripts()
            /// <summary>
            ///    Add date validation JavaScript to the Page
            /// </summary>
            /// <param name="e"></param>
            override protected void OnPreRender(EventArgs e)
            {
                  StringBuilder s = new StringBuilder();
                  s.Append("\n<SCRIPT LANGUAGE=javascript>\n");
                  s.Append("function tg_mm_daysinmonth(lnMonth,lnYear) {\n");
                  s.Append("var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn\n");
                  s.Append("lmn = lnMonth-1\n");
                  s.Append("dt1 = new Date(lnYear,lmn,1)\n");
                  s.Append("cmn1 = dt1.getMonth()\n");
                  s.Append("dtt=dt1.getTime()+2332800000\n");
                  s.Append("lflag = true\n");
                  s.Append("dycnt=28\n");
                  s.Append("while (lflag) {\n");
                  s.Append("   dtt = dtt + 86400000\n");
                  s.Append("   dt1.setTime(dtt)\n");
                  s.Append("   cmn2 = dt1.getMonth()\n");
                  s.Append("   if (cmn1!=cmn2) {\n");
                  s.Append("      lflag = false }\n");
                  s.Append("   else {dycnt = dycnt + 1}}\n");
                  s.Append("if (dycnt > 31) {dycnt = 31}\n");
                  s.Append("return dycnt\n");
                  s.Append("}\n");
                  s.Append("\n");
                  s.Append("function tg_mm_setdays(sobjname, datemode){\n");
            s.Append("var dobj = document.getElementsByName(sobjname + \"_day\")[0]\n");
            s.Append("var mobj = document.getElementsByName(sobjname + \"_month\")[0]\n");
            s.Append("var yobj = document.getElementsByName(sobjname + \"_year\")[0]\n");
            s.Append("var hobj = document.getElementsByName(sobjname)[0]\n");
            s.Append("var hobjconv = document.getElementsByName(sobjname + \"_conv\")[0]\n");

            //s.Append("var dobj = eval(sobjname + \"_day\")\n");
            //s.Append("var mobj = eval(sobjname + \"_month\")\n");
            //s.Append("var yobj = eval(sobjname + \"_year\")\n");
            //s.Append("var hobj = eval(sobjname)\n");
            //s.Append("var hobjconv = eval(sobjname + \"_conv\")\n");
                  s.Append("var monthdays = tg_mm_daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value)\n");
                  s.Append("var selectdays = dobj.length\n");
                  s.Append("var curdy = dobj.options[dobj.selectedIndex].value\n");
                  s.Append("if (curdy.length==1) {curdy = \"0\"+curdy}\n");
                  s.Append("var curmn = mobj.options[mobj.selectedIndex].value\n");
                  s.Append("if (curmn.length==1) {curmn = \"0\"+curmn}\n");
                  s.Append("var curyr = yobj.options[yobj.selectedIndex].value\n");
                  s.Append("if (selectdays > monthdays) {\n");
                  s.Append("   for (var dlp=selectdays; dlp > monthdays; dlp--) {\n");
                  s.Append("       dobj.options[dlp-1] = null }}\n");
                  s.Append("else if (monthdays > selectdays) {\n");
                  s.Append("   for (var dlp=selectdays; dlp < monthdays; dlp++) {\n");
                  s.Append("       dobj.options[dlp] = new Option(dlp+1,dlp+1) }}\n");
                  s.Append("if (curdy > monthdays) {\n");
                  s.Append("   dobj.options[monthdays-1].selected = true\n");
                  s.Append("   curdy = monthdays }\n");
                  s.Append("var curdateconv = curmn+\"/\"+curdy+\"/\"+curyr\n");
                  s.Append("if (datemode==1) {\n");
                  s.Append("   var curdate = curmn+\"/\"+curdy+\"/\"+curyr }\n");
                  s.Append("else if (datemode==2) {\n");
                  s.Append("   var curdate = curdy+\"/\"+curmn+\"/\"+curyr }\n");
                  s.Append("else if (datemode==3) {\n");
                  s.Append("   var curdate = curyr+curmn+curdy }\n");
                  s.Append("else if (datemode==4) {\n");
                  s.Append("   var cdate = new Date(curyr,curmn-1,curdy)\n");
                  s.Append("   var curdate = cdate.toGMTString() }\n");
                  s.Append("hobj.value = curdate\n");
                  s.Append("hobjconv.value = curdateconv\n");
                  s.Append("}\n");
                  s.Append("</SCRIPT>\n");
                  s.Append("\n");

                  // Add the Script to the Page
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "mm_datepicker", s.ToString());

        }

      }
}
0
 

Author Closing Comment

by:mathieu_cupryk
Comment Utility
it is of type string.
0
 
LVL 6

Expert Comment

by:RishadanPort
Comment Utility
Sorry for not being able to help more.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now