C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2008, 02:56 PM
jlmoshier jlmoshier is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 75 jlmoshier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 h 18 m 27 sec
Reputation Power: 5
Output C# on a page

Hello,
I am extremly new to C#. Actually this is my first attempt at writing code in C#.

We are changing our website from ASP written in vbscript to ASP.NET written in C#

I an trying to output a servervariable in an asp label. How would i transpose this vbscript code to c#.
Code:
<asp:Label runat="server" Text="<%=ServerVariable(LOGON_USER)%>" ID="Label1"></asp:Label>

Thanks for you help in advance
jlmoshier

Reply With Quote
  #2  
Old August 28th, 2008, 07:33 AM
Ronster Ronster is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Location: Charlotte
Posts: 210 Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Days 27 m 15 sec
Reputation Power: 113
Quote:
Originally Posted by jlmoshier
Hello,
I am extremly new to C#. Actually this is my first attempt at writing code in C#.

We are changing our website from ASP written in vbscript to ASP.NET written in C#

I an trying to output a servervariable in an asp label. How would i transpose this vbscript code to c#.
Code:
<asp:Label runat="server" Text="<%=ServerVariable(LOGON_USER)%>" ID="Label1"></asp:Label>

Thanks for you help in advance
jlmoshier


You're making the mistake of trying to make asp.net work like asp.

What you need to do is set the label.text property in the code behind page, in the PageLoad event.

label.text = Request.ServerVariables["LOGON_USER"] (those are SQUARE BRACKETS!, not parenthesis).

Look here for some comments on this issue:
http://support.microsoft.com/kb/306359
http://www.tek-tips.com/viewthread.cfm?qid=831679

Reply With Quote
  #3  
Old August 28th, 2008, 07:47 AM
jlmoshier jlmoshier is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 75 jlmoshier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 h 18 m 27 sec
Reputation Power: 5
Thanks for the help. I have another question. Maybe a simple one but did not think it mattered before but now I am not so sure.

We are using creating our website now on Sharepoint so I am using the designer to create a lot of the pages. I tried putting your code into my page. Here is what I have.
Code:
<asp:Label runat="server" Text="Request.ServerVariables['LOGON_USER']" ID="Label1"></asp:Label>

I guess my question is because there is no code behind page does the text="" have to change. When I use the above code all I am getting is the text literally on the page vs. the variable.

While I am at it i have another question. Do you know how I can get a substring of the variable. I want to strip off our domain name that is returned with the username.

Thanks for all your help.

Reply With Quote
  #4  
Old August 28th, 2008, 01:47 PM
Ronster Ronster is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Location: Charlotte
Posts: 210 Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Days 27 m 15 sec
Reputation Power: 113
Quote:
Originally Posted by jlmoshier
I guess my question is because there is no code behind page does the text="" have to change. When I use the above code all I am getting is the text literally on the page vs. the variable.


If there's no code behind page, it's done a little differently. The "code behind" stuff lives in a SCRIPT tag, something like this:

Code:
<script runat="server">
    	protected void Page_Load(object sender, EventArgs e)
	{

    
        label.Text = "blah blah"
    }
</script>



You can simply GOOGLE something like "asp.net with no code behind" or something and get some other info.

Same for the string processing you're looking for... just GOOGLE "asp.net c# string functions" and you'll get plenty of info.

Dude, GOOGLE is your friend! The questions you've asked so far, I"ve found answers for all of them with ONE (each) simple GOOGLE. Try it, you'll like it !!

Reply With Quote
  #5  
Old August 28th, 2008, 02:10 PM
jlmoshier jlmoshier is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 75 jlmoshier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 h 18 m 27 sec
Reputation Power: 5
Thanks for the help. But I am a girl
And i did try google before posting unfortunately i have never been good at using the correct keywords to get what i want.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Output C# on a page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT