Total Beginner Question

  • Thread starter Thread starter INTP56
  • Start date Start date
I

INTP56

I have a need to get the current logged on user and pass that value on to a
database. WHile ASP:LoginName displays the right value, I can't seem to
figure out how to use that value anywhere else. I've included some very basic
code, and I'm wondering if someone can show me how to get the login name into
a text box. I have figured out how to use a value in a textbox as a parameter
(If I just set it to a valid value).

TIA, Bob

Here is some code I've tried.

<%@ Page Language="C#" %>
<html dir="ltr">

<head runat="server">
<META name="WebPartPageExpansion" content="full">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled 1</title>
</head>

<body>

<form id="form1" runat="server">
LoginControl:
<asp:LoginName
runat="server"
id="LoginName1"/>
<br>
<br>
TextBox:
<asp:TextBox
runat="server"
id="TextBox1"
text="What do I put here to get the value of LoginName1?"
Width="378px">
</asp:TextBox>
<br>
TestBox1:
<asp:TextBox
runat="server"
id="TestBox1"
text=Request.ServerVariables("LOGON_USER")
Width="378px">
</asp:TextBox>
<br>
TestBox2:
<asp:TextBox
runat="server"
id="TestBox2"
text=User.Identity.Name
Width="378px">
</asp:TextBox>
<br>
TestBox3:
<asp:TextBox
runat="server"
id="TestBox3"
text=HttpContext.Current.User.Identity.Name
Width="378px">
</asp:TextBox>
<br>
TestBox4:
<asp:TextBox
runat="server"
id="TestBox4"
text='<%Session("Username")%>'
Width="378px">
</asp:TextBox>
<br>
</form>

</body>

</html>
 
Hi,

Have You tried setting the Text property of the textbox from code (at page
load for example)?

Zsolt
 
<asp:TextBox
        runat="server"
        id="TestBox1"
        text=Request.ServerVariables("LOGON_USER")
        Width="378px">
</asp:TextBox>

Must be

text='<%# Request.ServerVariables("LOGON_USER") %>'

Hope this helps
 
Alexey,

When I made the suggested change:

TestBox2:
<asp:TextBox
runat="server"
id="TestBox2"
text='<%# Request.ServerVariables("LOGON_USER") %>'
Width="378px">
</asp:TextBox>

I got the following error message:

An error occurred during the processing of . Code blocks are not allowed in
this file.
Troubleshoot issues with Windows SharePoint Services.

Is this a sharepoint problem?

Bob
 
INTP56 said:
When I made the suggested change:

TestBox2:
<asp:TextBox
runat="server"
id="TestBox2"
text='<%# Request.ServerVariables("LOGON_USER") %>'
Width="378px">
</asp:TextBox>

I got the following error message:

An error occurred during the processing of . Code blocks are not
allowed in this file.
Troubleshoot issues with Windows SharePoint Services.

Is this a sharepoint problem?

No; your life will be much simpler if you follow miher's suggestion.

On the View menu, choose "Code". There will be a Page_Load section inside
which you could put

TextBox1.Text=HttpContext.Current.User.Identity.Name


Remember that changes to the "code behind" don't take effect until you build
the project.

Some info on code behind:
http://www.4guysfromrolla.com/webtech/100500-1.shtml
http://en.wikipedia.org/wiki/ASP.NET

HTH

Andrew
 
Alexey,

When I made the suggested change:

TestBox2:
<asp:TextBox
        runat="server"
        id="TestBox2"
        text='<%# Request.ServerVariables("LOGON_USER") %>'
        Width="378px">
</asp:TextBox>

I got the following error message:

An error occurred during the processing of . Code blocks are not allowed in
this file.
Troubleshoot issues with Windows SharePoint Services.

Is this a sharepoint problem?

Bob, it is.

To get this working you need to modify the web.config file. To allow
server side script on pages you have to modify the PageParserPaths
into:

<pageparserpaths>
<pageparserpath virtualpath="..." compilationmode="Always"
allowserversidescript="True" includesubfolders="..." >
</pageparserpaths>

Please refer to SharePoint documentation or ask in Sharepoint related
newsgroup
 
Back
Top