?
Solved

How do I retrieve a userID and display in the aspx page?

Posted on 2011-10-28
5
Medium Priority
?
475 Views
Last Modified: 2012-05-12
I am new to C# and the syntax is killing me. I need to retrieve the users network ID from the codebehind and display it on the web page.

The codebehind is as follows:

        protected string UserIDtxt;

        public string getUserID
        {
            UserIDtxt = Environment.UserName.ToString()
            return UserIDtxt;
        }
I get the error: A get or set accessor is expected.

The web page code is <%= getUserID%>

Any ideas?
0
Comment
Question by:lizziesboy
  • 4
5 Comments
 
LVL 4

Expert Comment

by:erik_nodland
ID: 37045737
I think it is because you are calling it as a property but you want to call it as a method.

So try

<%= getUserID()%>

thanks

0
 
LVL 4

Expert Comment

by:erik_nodland
ID: 37045760
Forgot to give you the other bit. Note the brackets!

protected string UserIDtxt;

 public string getUserID()
        {
            UserIDtxt = Environment.UserName.ToString()
            return UserIDtxt;
        }
 In your web page code

<%= getUserID()%>

If you do want it as a property then use this instead


protected string UserIDtxt;

 public string getUserID
        {
            UserIDtxt = Environment.UserName.ToString()
            return UserIDtxt;
        }
 In your web page code

<%= getUserID()%>

If you really do want to use it as a property then use this

public string getUserID
        {
            get { return Environment.UserName.ToString(); }
        }

Web page code

<%= getUserID%>

thanks


0
 
LVL 4

Expert Comment

by:erik_nodland
ID: 37045772
Not sure whats going on my text is all over the place. Here you go again!

protected string UserIDtxt;

 public string getUserID()
        {
            UserIDtxt = Environment.UserName.ToString()
            return UserIDtxt;
        }
 In your web page code

<%= getUserID()%>

If you really do want to use it as a property then use this

public string getUserID
        {
            get { return Environment.UserName.ToString(); }
        }

Web page code

<%= getUserID%>

thanks

0
 

Author Comment

by:lizziesboy
ID: 37045997
I cut and pasted your second version and I still get the undline under UserIDtxt that says a get or set expected.
0
 
LVL 4

Accepted Solution

by:
erik_nodland earned 2000 total points
ID: 37046066
Hi

The second version shouldn't have a UserIDtxt part to it. You should just use the following without the protected field.

public string getUserID
        {
            get { return Environment.UserName.ToString(); }
        }

thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question