I want textbox in my page to capture user name after user login.
I tried using the code below,but nothing happens,the textbox is still empty.
Anyone knows what is wrong with this code?
Did i missed something here?
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web.Caching;
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 Project
{
public partial class Master : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
TextBox1.Text = "Welcome " + User.Identity.Name;
}
else
{
TextBox1.Text = "Welcome user";
}
}
}
}
samPosted Aug 24, 2010, 8:55 PM
[code]
protected void Page_Load(object sender, System.EventArgs e)
{
string getname = Page.User.Identity.Name;
TextBox1.Text = getname;
}
[/code]
I put the above code in the (aspx) page as a script.
Dont know why when i put the code behind (cs),it is not working.
I believe my code prevoiusly to work when i put in aspx page as script.
Means,the code will be like this:
[code]
[/code]
thanks for the guide abhi.
Abhimanyu K VatsaPosted Aug 20, 2010, 4:34 AM
i think you are wishing to display the username in any textbox when user logins. I hope textbox is existed on redirected page after user login, right?
try this code inside click event or say inside login button click event.
session(username)=textboxname.text
and then use this session in your redirected page load.
this is my concept for that, you have change it yourself to run properly.
hope it helped you