Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7708381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:35:53+00:00 2026-06-01T00:35:53+00:00

Currently I have a DateTime property for a model. I am using the telerik

  • 0

Currently I have a DateTime property for a model. I am using the telerik MVC framwork but I am using a DateTime property and the editor column for this property is auto-generated so there is no code which controls it in my View or Controller. On Telerik’s website there are instructions on how to set the default date time for a date time picker but this picker isn’t initiated anywhere because it is in a column. The problem is I want to set the DateTime to be the current date and time if it isn’t already specified. Currently, the code for the model looks like this:

 public DateTime CreatedDate { get; set;}

I want it to do something more like this:

public DateTime CreatedDate
        {
            get
            {
                if (QuestionID != 0)
                {
                    return this.CreatedDate;
                }
                else
                {
                    return DateTime.Now;
                }

            }
            set { CreatedDate = value; }
        }

this way it will return the DateTime that is stored for this Question if the ID exists. If you are creating a new Question, it gets the current DateTime.

The problem is here with the Set. When I try to load up a screen, set get’s a Stack Overflow. I’m really unfamilular with this kind of code, so I have no idea how to work with it.

Before we were not working with the model, and instead using JQuery to get the CreatedDate’s data and set it to the current date time. The issue with that is when you go to the “picker” part of the date time, it goes to the default date time rather than the current one. this is why I want to set it through the Model, View, or Controller, and not with Jquery.

Let me know if you can help me understand Gets and Sets in the model!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:35:54+00:00Added an answer on June 1, 2026 at 12:35 am

    You need to have a private property you are using behind the scenes.

        private DateTime _createdDate;
        public DateTime CreatedDate
        {
            get
            {
                if (QuestionID != 0)
                {
                    return _createdDate;
                }
                else
                {
                    return DateTime.Now;
                }
    
            }
            set { _createdDate = value; }
        }
    

    You are getting an overflow because you are doing something like this currently:

    CreatedDate = 1/1/2012;
    ...which then calls
    CreatedDate = 1/1/2012;
    ...which then calls
    CreatedDate = 1/1/2012
    ..You get the point (it is continuously setting itself until the stack overflows)
    

    Auto implemented properties ({get;set;}) actually use a private variable behind the scenes. If you were to look at the IL, then you would see that it actually breaks that simple {get;set;} into a getter/setter based on a generated private variable. They are just a type of “compiler magic” to cut down on boilerplate code of having to create a private variable when there is no real logic in the getter/setter. If you have logic, then you need to implement this private variable yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that is currently using the datetime microformat to display a
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
Using C# and .Net 4.0 I have a generated schema that looks like this:
I have db model, where one property has auto_now_add=True . But looks like it
I have a DateTime? field. Its currently storing UT. I would like it to
I have a database with DateTime fields that are currently stored in local time.
I currently have an existing database and I am using the LINQtoSQL generator tool
I currently have a fairly robust server-side validation system in place, but I'm looking
We have a complex business model and is using NHibernate to create and maintain
I am currently trying to add a custom column name to a property in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.