Hi.
I have a code here where the loginname will display the computer name.
I have another textbox,where i want the same loginname value to be displayed in the textbox.
Any ideas on how to do this,guys?
Here's my code :
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<br />
<br />
<br />
welcome <asp:LoginName ID="LoginName1" runat="server" />//THIS LOGIN NAME TO BE DISPLAYED IN TEXTBOX 2 BELOW <br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
SelectCommand="SELECT [ApplicationName], [LoweredApplicationName] FROM [vw_aspnet_Applications]">
</asp:SqlDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<EditItemTemplate>
ApplicationName: <asp:TextBox ID="ApplicationNameTextBox" runat="server"
Text='<%# Bind("ApplicationName") %>' />
<br />
LoweredApplicationName: <asp:TextBox ID="LoweredApplicationNameTextBox" runat="server"
Text='<%# Bind("LoweredApplicationName") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
ApplicationName: <asp:TextBox ID="ApplicationNameTextBox" runat="server"
Text='<%# Bind("ApplicationName") %>' />
<br />
LoweredApplicationName: <asp:TextBox ID="LoweredApplicationNameTextBox" runat="server"
Text='<%# Bind("LoweredApplicationName") %>' />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
ApplicationName: <asp:Label ID="ApplicationNameLabel" runat="server"
Text='<%# Bind("ApplicationName") %>' />
<br />
LoweredApplicationName: <asp:Label ID="LoweredApplicationNameLabel" runat="server"
Text='<%# Bind("LoweredApplicationName") %>' />
<br />
<asp:TextBox ID="TextBox2" runat="server" ToolTip="TextBox2"></asp:TextBox>//DISPLAY LOGINNAME VALUE ABOVE INTO THISTEXTBOX <br />
<br />
</ItemTemplate>
</asp:FormView>
<br />
</LoggedInTemplate>
<AnonymousTemplate>
please login<br />
<br />
<br />
<asp:Login ID="Login1" runat="server">
</asp:Login>
<br />
<br />
<br />
</AnonymousTemplate>
</asp:LoginView>
</div>
</form>
</body>
</html>
|
samPosted Sep 16, 2010, 11:35 PM
Here's my cs code :
[code]
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace SaveForm
{
public partial class findcontrol : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string name = Page.User.Identity.Name;
((TextBox)((FormView)LoginView1.FindControl("FormView1")).FindControl("TextBox2")).Text = name;//gives error in this line
}
}
}
[/code]
My aspx code is the same as above (my first post).
AnkurPosted Sep 14, 2010, 2:57 AM
the solution provided is working fine on my system..could not regenerate the error you mentioned. could you please post more of the cs and aspx code.
Thanks and Regards
samPosted Sep 14, 2010, 2:17 AM
Hi.It shows the following error:
Object reference not set to an instance of an object.
Line 20: string name = Page.User.Identity.Name; Line 21: ((TextBox)((FormView)LoginView1.FindControl("FormView1")).FindControl("TextBox2")).Text = name;AnkurPosted Sep 14, 2010, 1:11 AM
cs:
string name = Page.User.Identity.Name;
((TextBox)((FormView)LoginView1.FindControl("FormView1")).FindControl("TextBox2")).Text = name;
Thanks and Regards