#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    11

    Property access must assign to the property or use its value


    Hello,

    I'm trying to add the value of my textbox to a viewstate but I receive this error "property access must assign to the property or use its value"

    Dim s As String
    ViewState.add["s"] = TextBox1.text
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2006
    Location
    San Diego, USA
    Posts
    527
    Rep Power
    148
    It appears that you are working with VB.NET.

    Your first line is not needed, so you can remove it (it doesn't do anything in your example):
    Dim s As String

    Your second line needs to be changed to either:
    ViewState.add("s", TextBox1.Text)
    or
    ViewState("s") = TextBox1.Text

    ...Or something like that.
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Middle TN
    Posts
    504
    Rep Power
    18
    Originally Posted by imperialx
    Hello,

    I'm trying to add the value of my textbox to a viewstate but I receive this error "property access must assign to the property or use its value"
    That error message is *very* straightforward. You are not using the value you specified in your property setter. It looks like you left off a little information in your code snippet. Here, I'll go ahead and add it for you:

    [code=Visual Basic .NET]Public Property MyProperty() As String
    ' snipped Get method
    Set(ByVal Value As String)
    Dim s As String
    ViewState.add["s"] = TextBox1.text
    End Set
    End Property[/code]

    Now, here's the problem: When you create a setter method for a property, you have to use the value that's passed to the property. You specify it by name in the Set(...) portion of the setter. In this case, the name is Value, but you can call it whatever you like, so long as you use it in your setter.

    It looks like you're new to the concept. You should probably read up on properties. Try here:

    http://msdn2.microsoft.com/en-us/lib...classes_topic3

    I'm guessing here, but it looks like what you wanted to do was something along the lines of the following:

    [code=Visual Basic .NET]Public Property MyProperty() As String
    Get
    return ViewState("MyProperty")
    End Get
    Set(ByVal Value As String)
    ViewState("MyProperty") = Value
    End Set
    End Property

    ' Elsewhere in your code:
    MyProperty = TextBox1.Text[/code]
    Last edited by Randolpho; April 30th, 2007 at 09:28 AM. Reason: teehee, I slipped into C# there.
    Bad code monkey! No banana!

IMN logo majestic logo threadwatch logo seochat tools logo