Accessing control properties...

I just thought I'd mess around with C# and see what the hell it has to offer and - I feel like a complete newbie!

I don't know whether it is my VS2005 playing around, but I cannot seem to assign any values to control properties.

For example, I get the error on this line:

myLiteral.Text = str.ToString;   //str is a stringbuilder....

The error i get is:

Error      1      An object reference is required for the nonstatic field, method, or property '_Default.myLiteral'      c:\inetpub\wwwroot\c_stream\streaming.aspx.cs      48      9      http://localhost/c_stream/

What is going on!


LVL 11
Ramesh SrinivasTechnical ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

At first glance, I'd say you need to call ToString with brackets, as it is a method, not a property.
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Yes, that is prob true, but even with brackets I get the same error :(

I cannot seem to reference any controls like this. Works fine when I create a VB.Net project.
Ramesh SrinivasTechnical ConsultantAuthor Commented:
When I installed visual studio 2005, I did set the default language option to VB.NET.

Now that I have created a C# project, maybe it has bugged because of some operations occuring during installation??!

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ramesh SrinivasTechnical ConsultantAuthor Commented:
When I type Literal1.    intellisense does nto show any properties e.g., Text, ID etc etc...

It is doing this for any controls i place on the page.  If I use the word this. then intellisense shows me the name of the control i placed on the page and also its properties. But when I try to compile I get an error:

Error      1      Keyword 'this' is not valid in a static property, static method, or static field initializer      c:\inetpub\wwwroot\c_stream\streaming.aspx.cs      48      9      http://localhost/c_stream/

Damn it.
Still not altogether sure how far you've got with this, and I'm no ASP guru, but it sounds like you are trying to use "this" and your other control references in a static method, which of course can be called when no object instance has yet been created. , e.g. MyClass.InstanceCount can be zero; or there may be more than one instance to which "this" could refer, in which case the reference would be ambiguous.

"this" is how an instance refers to itself. There is, to my knowledge no explicit at the class level meaning the class itself.

Sorry if you already know all this (!). Good luck!

Not sure why it would work OK in VB, though.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ramesh SrinivasTechnical ConsultantAuthor Commented:
I think it was because I was referencing the control from a static method as you mentioned.

A bit confusing seen as tho in vb you can reference a control from a sub function etc etc.

Not at all - shy
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.