Error: Property access must assign to the property or use its value.

Hello,

I am having a problem and I am not sure what I am doing wrong with my property:

Private ReadOnly Property returnUsername() As String

Get

If Page.IsPostBack() = True Then

returnUsername = ToString(usernametxt.Text)

Return returnUsername

Else

returnUsername = ""

Return returnUsername

End If

End Get

End Property

 I getting the error: Property Access must assign to the property or use its value.

 I thought I was already doing that. Any help will be greatly appreciated.

Thanks

0
gatoress 8/25/2008 11:25:47 AM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 7 followers.

💬 5 Replies
👁️‍🗨️ 139 Views

 I think you cannot use page.ispostback() from the property(i think/not sure) . modify you code by the following instruction.

 

1. declare a  public Boolean  variable into the beging of your class name blnIsPostBack.


2. in the page_load event write the following code

page_load()

        blnIsPostBack=false

if page.ispostBack ()=true then

    blnIsPostBack=true

end if

end page_load///// i donot  know vb well

3. modify your property as 

 Private ReadOnly Property returnUsername() As String

Get

If blnIsPostBack = True Then

returnUsername = ToString(usernametxt.Text)

Return returnUsername

Else

returnUsername = ""

Return returnUsername

End If

End Get

End Property

 

I think it will work for you.I am weak in vb code. for further query ask me.


Shafiul hasan md. tareq
plz marked as answer if it helps you for future developers who are facing same problem.:)

0
Tareq_sust 8/25/2008 2:09:49 PM

You are assigning the value to the property and the property does not have a setter. Even if it has a setter this is not a good practice.

What are you trying to accomplish? Please explain details. Anyway, here is the code that will work although this is not the best practice. 

Public ReadOnly Property ReturnUserName() As String
    Get
                Dim userName As String =  String.Empty
 
                if(Page.IsPostBack)
                {
                    userName = "azamsharp"
                    Return userName
                }
                else
                {
                    Return userName
                }
 
    End Get
End Property

 


HighOnCoding
Wanna get high!
0
azamsharp 8/25/2008 2:24:43 PM

I rewrote my Property to the following and it worked:

Private ReadOnly Property returnUsername() As String

Get

If Page.IsPostBack() = True Then

returnUsername = usernametxt.Text.ToString()

Return returnUsername

Else

returnUsername = ""

Return returnUsername

End If

 

End Get

 

But what do you mean by the property does not have a setter? What I am trying to do is send the login information from one page to another that is in a different application/website. I have a login page which uses server form controls to validate the data but I am then trying to get the information after postback to send to a different application, using hiddent input fields.

I am not happy with the way I am doing this, since it is not secure at all and i am finding all the login information is displayed in ViewState when data is redirected to postBackURL.

Any help will be greatly appreciated!

Thanks

0
gatoress 8/25/2008 2:55:18 PM

 How are you doing this:

returnUsername = usernametxt.Text.ToString()

Your property does not contain the setter and you are setting the property. How does it even compile? 


HighOnCoding
Wanna get high!
0
azamsharp 8/25/2008 3:02:16 PM

It compiles and runs! At first the page loads with no value for usernametxt ( a textbox).

But after a value is entered and submited, the hidden input values call the returnUsername() property.

 

0
gatoress 8/25/2008 3:15:38 PM
Reply:
Similar Posts: