By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

how to display user name after login page using c#

P: 7
Hello!!!

Can any one tell how to retrieve user name and other details like first name,address,contact no. and so on.... and display in welcome page after login page using c# and sql server plzzzzzzzzzzzz



Thanking u

Regards,
Deepshika
Nov 15 '07 #1
Share this Question
Share on Google+
3 Replies


debasisdas
Expert 5K+
P: 8,127
Dear Deepshika

Can you kindly post what you have tried so far to solve the mentioned problem.
Nov 15 '07 #2

P: 7
Dear Deepshika

Can you kindly post what you have tried so far to solve the mentioned problem.

<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="mainTable" border="0" style="Z-INDEX: 103; LEFT: 544px; WIDTH: 264px; POSITION: absolute; TOP: 96px; HEIGHT: 296px">
<TBODY>
<tr>
<td>
<table class="t_border" id="loginTable" cellspacing="15" cellpadding="0">
<tr>
<td align="center" colspan="2"><b>USER LOGIN</b></td>
</tr>
<tr>
<td><b>Login: </b>
</td>
<td><asp:textbox id="txtUserName" runat="server" width="128px" BackColor="LightGray" Font-Bold="True"></asp:textbox><asp:requiredfieldvalidator id="rvUserValidator" runat="server" controltovalidate="txtUserName" errormessage="You Must Enter a EmployeeId!"
display="None">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td style="HEIGHT: 23px"><b>Password: </b>
</td>
<td style="HEIGHT: 23px"><asp:textbox id="txtPassword" runat="server" width="128px" textmode="Password" BackColor="LightGray"
Font-Bold="True"></asp:textbox><asp:requiredfieldvalidator id="rvPasswordValidator" runat="server" controltovalidate="txtPassword" errormessage="Empty Passwords not accepted"
display="None">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td align="center" colspan="2"><asp:button id="cmdSubmit" runat="server" text="Submit" borderstyle="Solid" Font-Bold="True"></asp:button></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="messageDisplay">
<tr>
<td><asp:validationsummary id="Validationsummary1" runat="server" width="248px" displaymode="BulletList" Height="40px"></asp:validationsummary></td>
</tr>
</table>
</td>
</tr>
</TBODY>
</table>
</form>
<asp:label id="lblMessage2" runat="server" width="264px" font-bold="True" font-italic="True"
font-size="Medium" forecolor="#C00000" style="Z-INDEX: 101; LEFT: 544px; POSITION: absolute; TOP: 432px"></asp:label>
<asp:label id="lblMessage" runat="server" width="264px" font-bold="True" font-italic="True"
font-size="Medium" forecolor="#C00000" style="Z-INDEX: 102; LEFT: 544px; POSITION: absolute; TOP: 400px"></asp:label></TR></TBODY></TABLE>
</body>
</HTML>




private void cmdSubmit_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
{
FormsAuthentication.RedirectFromLoginPage (txtUserName.Text, false);
Response.Redirect ("Success.aspx");
}
else
{
lblMessage.Text = "Invalid Login, please try again!";
}
}

}
private bool DBConnection(string txtUser, string txtPass)
{

SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCmd = new SqlCommand("ValidateUser", myConn);
myCmd.CommandType = CommandType.StoredProcedure;

SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter returnParam;

objParam1 = myCmd.Parameters.Add ("@EmployeeNumber", SqlDbType.VarChar);
objParam2 = myCmd.Parameters.Add ("@EMPPassword", SqlDbType.VarChar);
returnParam = myCmd.Parameters.Add ("@Num_of_User", SqlDbType.Int);

objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
returnParam.Direction = ParameterDirection.ReturnValue;

objParam1.Value = txtUser;
objParam2.Value = txtPass;

try
{
if (myConn.State.Equals(ConnectionState.Closed))
{
myConn.Open();
myCmd.ExecuteNonQuery();
}
if ((int)returnParam.Value < 1)
{
lblMessage.Text = "Invalid Login!";
return false;
}
else
{
myConn.Close();
return true;
}
}
catch (Exception ex)
{

lblMessage2.Text = ex + "Error Connecting to the database";
return false;
}

}
Nov 15 '07 #3

P: 7
above code is my login page if enter "login is nothing but employee number" if i enter employee number it should display employee name and other details in welcome page
Nov 15 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.