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 7502603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:55:43+00:00 2026-05-29T20:55:43+00:00

I am building a code behind page that has a public property (MyDTOItem) which

  • 0

I am building a code behind page that has a public property (MyDTOItem) which is essentially a DTO object (dtDTOItem) Note: In my code the Get and Set are actually real code (I stripped it for the example).

The problem I am having is in the Page_Load event. When I set the .Member1 property of the DTO object the Get code runs and not the Set and therefore the DTO ibject property .Member1 never gets assigned.

I figured out that if I add code (MyDTOItem = New dtDTOItem) to the Page_Load event then it will set the value correctly. What I am trying to figure out is how to initialize the property object without having to do it explicitly. It has to be an extended property because I have custom Get and Set code.

Thank you in advance.

Public Property MyDTOItem As dtDTOItem
    Get

    End Get
    Set(value As dtDTOItem)

    End Set
 End Property


<DataContract(), Serializable()> _
Public Class dtDTOItem

  <DataMember()> _
  Property Member1 As String = ""

  <DataMember()> _
  Property Member2 As String = ""

  <DataMember()> _
  Property Member3 As String = ""

End Class


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    MyDTOItem.Member1 = "temp string"
End Sub
  • 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-05-29T20:55:46+00:00Added an answer on May 29, 2026 at 8:55 pm

    You must instantiate the field that backs your MyDTOItem property before attempting to set property values on it. You don’t get to cheat and not instatiate an object before you start messing with its members.

    Example:

    Private oBackingField As SomeObject = New SomeObject

    Public Property VisibleProperty As SomeObject
    Get

    End Get
    …. etc.

    No events involved. Well.. it probably works out to the Init or PreInit event.. but you dont have to worry your pretty little head about that.

    EDIT 2

    Prior to .NET 4 you had to craft all your properties with backing fields, and even still to this day if you provide property accessors you must provide your own backing field… it looked like this:

    Private backingField As DataType = New DataType  ' Create backing field and initialize it
    
    Public Property forwardFacingProperty As DataType
    Get
      Return backingField
    End Get
    Set (byval tValue as DataType)
      backingField = tValue
    End Set
    End Property
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an aspx page that uses jquery ajax to post values, which are
I've been using Visual Studio's property sheets for building my code and I have
im building a forum and now im gonna code the thread page. is there
I am building some basic HTML code for a CMS. One of the page-related
I am building an XML document successfully with the following code: public function build($result)
I need some guidelines about building the code behind of my pages correctly. I
I picked up some code that is building a Gridview with a SQLDataAdapter. One
I have a WPF UserControl. The code behind file declares some RoutedUICommand objects which
I'm building an asp.net page that uses a page method call from jquery. This
I'm building a html table dynamically in an ASP.NET code behind file using C#.

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.