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.
[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).
AnkurRank #1,353 · 1.2K reputationPosted Sep 13, 2010, 9:11 PM EDT
cs:
string name = Page.User.Identity.Name;
((TextBox)((FormView)LoginView1.FindControl("FormView1")).FindControl("TextBox2")).Text = name;
Thanks and Regards
sam147 reputationPosted Sep 13, 2010, 10:17 PM EDT
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;AnkurRank #1,353 · 1.2K reputationPosted Sep 13, 2010, 10:57 PM EDT
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
sam147 reputationPosted Sep 16, 2010, 7:35 PM EDT
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).