I need to save the user name in a sql table, example: an user
put it’s user name and password in the login, then, in other form must
send some data in textboxes to another user, how can I save the username?
I’m working in a website with visual studio 2008, c sharp and sql server 2005, thanks
in advance.
this is my code in login and I have to pass the user name to the 2nd form
protected void btnLogin_Click(object sender, EventArgs e)
{
ClPersona login = new ClPersona();
bool isAuthenticated = login.sqlLogin1((txtUsuario.Text), (txtPassword.Text));
if (isAuthenticated)
{
//prueba para sesion
Session["sesionicontrol"] = login.NombreUsuario;
Response.Redirect("../MENU/menu1.aspx");
}
Drop a label on your target form like this:
Go to code behind of the target page find method
Page_Loadand add following code:This will read the value of
login.NombreUsuariohich was saved previously intoSession["sesionicontrol"]and display it in label.Assuptions I made are that:
login.NombreUsuario– contains the data you are reffering as user name – and that’s what you want to pass along.string.Generally
Sessionprivides a dictionary to save any named objects. They are shared between all pages inside current session. You can use session to pass some data across pages like this:WebForm1.aspx
WebForm1.aspx.cs
This saves the value you have just entered in
TextBoxinto session.WebForm2.aspx
WebForm2.sapx.cs
This fetches the values you have stored in previous page uner key
SomeKeyand sets it toLabelbefore the page gets rendered. You see the text you have entered on the forst page.