Range Validator - Newby - Help:)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Q2hyaXMgRA==?=

    Range Validator - Newby - Help:)

    Hi - I was hoping to use the range validator to check that the user's age is
    between 10 & 65 based upon an entered DOB. I thought I could use max&min date
    variables in the Validator & have those populated in the page_load event
    based on today's date. Dead end so far. Please HELP! Many thanks ... c
  • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

    #2
    Re: Range Validator - Newby - Help:)

    Chris D wrote:
    Hi - I was hoping to use the range validator to check that the user's age is
    between 10 & 65 based upon an entered DOB. I thought I could use max&min date
    variables in the Validator & have those populated in the page_load event
    based on today's date.
    Yes, that sounds plausible.
    Dead end so far. Please HELP! Many thanks ... c
    Well, what did you try?

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • =?Utf-8?B?Q2hyaXMgRA==?=

      #3
      Re: Range Validator - Newby - Help:)

      Hi Goran & thanks for helping. This is what I have ...
      protected void Page_Load(objec t sender, EventArgs e)
      {
      DateTime theDate, maxDate, minDate;
      theDate = DateTime.Parse( DateTime.Now);
      minDate = theDate.AddYear s(-65);
      maxDate = theDate.AddYear s(-10);
      }

      And this in the aspx
      <asp:TextBox ID="tbDOBchk" runat="server"> </asp:TextBox>
      <asp:RangeValid ator ID="rvDOBchk" Type="Date" runat="server"
      ControlToValida te="tbDOBchk" ErrorMessage="R angeValidator"
      MaximumValue="m axDate"
      MinimumValue="m inDate">message </asp:RangeValida tor>




      "Göran Andersson" wrote:
      Chris D wrote:
      Hi - I was hoping to use the range validator to check that the user's age is
      between 10 & 65 based upon an entered DOB. I thought I could use max&min date
      variables in the Validator & have those populated in the page_load event
      based on today's date.
      >
      Yes, that sounds plausible.
      >
      Dead end so far. Please HELP! Many thanks ... c
      >
      Well, what did you try?
      >
      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      >

      Comment

      • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

        #4
        Re: Range Validator - Newby - Help:)

        Chris D wrote:
        Hi Goran & thanks for helping. This is what I have ...
        protected void Page_Load(objec t sender, EventArgs e)
        {
        DateTime theDate, maxDate, minDate;
        theDate = DateTime.Parse( DateTime.Now);
        The DateTime.Now property returns a DateTime value, so you should not
        parse it. By doing so you force an implicit conversion to string, which
        you then parse into a DateTime value identical to the one that
        DateTime.Now returned.

        theDate = DateTime.Now.

        However, for your application the time is irrelevant, so you would
        rather use the Today property:

        theDate = DateTime.Today;
        minDate = theDate.AddYear s(-65);
        maxDate = theDate.AddYear s(-10);
        }
        >
        And this in the aspx
        <asp:TextBox ID="tbDOBchk" runat="server"> </asp:TextBox>
        <asp:RangeValid ator ID="rvDOBchk" Type="Date" runat="server"
        ControlToValida te="tbDOBchk" ErrorMessage="R angeValidator"
        MaximumValue="m axDate"
        MinimumValue="m inDate">message </asp:RangeValida tor>
        You can't use variable names as property values. The control parses the
        arguments, it doesn't evaluate them.

        You should set the arguments from the Page_Load method:

        rvDOBchk.Minimu mValue = minDate;
        rvDOBchk.MAximu mValue = maxDate;

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

          #5
          Re: Range Validator - Newby - Help:)

          Göran Andersson wrote:
          Chris D wrote:
          >Hi Goran & thanks for helping. This is what I have ...
          >protected void Page_Load(objec t sender, EventArgs e)
          > {
          > DateTime theDate, maxDate, minDate;
          > theDate = DateTime.Parse( DateTime.Now);
          >
          The DateTime.Now property returns a DateTime value, so you should not
          parse it. By doing so you force an implicit conversion to string, which
          you then parse into a DateTime value identical to the one that
          DateTime.Now returned.
          >
          theDate = DateTime.Now.
          >
          However, for your application the time is irrelevant, so you would
          rather use the Today property:
          >
          theDate = DateTime.Today;
          >
          > minDate = theDate.AddYear s(-65);
          > maxDate = theDate.AddYear s(-10);
          > }
          >>
          >And this in the aspx
          ><asp:TextBox ID="tbDOBchk" runat="server"> </asp:TextBox>
          > <asp:RangeValid ator ID="rvDOBchk" Type="Date"
          >runat="serve r" ControlToValida te="tbDOBchk" ErrorMessage="R angeValidator"
          > MaximumValue="m axDate"
          >MinimumValue=" minDate">messag e</asp:RangeValida tor>
          >
          You can't use variable names as property values. The control parses the
          arguments, it doesn't evaluate them.
          Also, the variables are local in the Page_Load method, so you would not
          be able to reach them from the markup code.

          Also, the Page_Load method runs after the markup is parsed, so even if
          you could reach the variables, their values would not yet have been set.

          So, in conclusion, the unreachable variables that you did not use
          doesn't exist yet. ;)
          You should set the arguments from the Page_Load method:
          >
          rvDOBchk.Minimu mValue = minDate;
          rvDOBchk.MAximu mValue = maxDate;
          >

          --
          Göran Andersson
          _____
          Göran Anderssons privata hemsida.

          Comment

          • =?Utf-8?B?Q2hyaXMgRA==?=

            #6
            Re: Range Validator - Newby - Help:)

            Huge thanks Goran. I learned a whole lot from you!!!

            "Göran Andersson" wrote:
            Göran Andersson wrote:
            Chris D wrote:
            Hi Goran & thanks for helping. This is what I have ...
            protected void Page_Load(objec t sender, EventArgs e)
            {
            DateTime theDate, maxDate, minDate;
            theDate = DateTime.Parse( DateTime.Now);
            The DateTime.Now property returns a DateTime value, so you should not
            parse it. By doing so you force an implicit conversion to string, which
            you then parse into a DateTime value identical to the one that
            DateTime.Now returned.

            theDate = DateTime.Now.

            However, for your application the time is irrelevant, so you would
            rather use the Today property:

            theDate = DateTime.Today;
            minDate = theDate.AddYear s(-65);
            maxDate = theDate.AddYear s(-10);
            }
            >
            And this in the aspx
            <asp:TextBox ID="tbDOBchk" runat="server"> </asp:TextBox>
            <asp:RangeValid ator ID="rvDOBchk" Type="Date"
            runat="server" ControlToValida te="tbDOBchk" ErrorMessage="R angeValidator"
            MaximumValue="m axDate"
            MinimumValue="m inDate">message </asp:RangeValida tor>
            You can't use variable names as property values. The control parses the
            arguments, it doesn't evaluate them.
            >
            Also, the variables are local in the Page_Load method, so you would not
            be able to reach them from the markup code.
            >
            Also, the Page_Load method runs after the markup is parsed, so even if
            you could reach the variables, their values would not yet have been set.
            >
            So, in conclusion, the unreachable variables that you did not use
            doesn't exist yet. ;)
            >
            You should set the arguments from the Page_Load method:

            rvDOBchk.Minimu mValue = minDate;
            rvDOBchk.MAximu mValue = maxDate;
            >
            >
            --
            Göran Andersson
            _____
            Göran Anderssons privata hemsida.

            >

            Comment

            Working...