|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Quote:
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Quote:
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 !! |
|
#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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Output C# on a page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|