C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




wants to show loginname into all pages


Posted Date: 31 Jul 2007      Total Responses: 2

Posted By: samir dutta       Member Level: Gold     Points: 2


dear all

After Login I would like to show Username into all pages, I have done the following code. what extra peace of coding required, please help

Step 1 Login Page :
-------------------
Imports System.Data
Imports System.Data.SqlClient

Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
End Sub

Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
Try
con.Open()
cmd = New SqlCommand("Select username,userpass from test where username='" & Me.txtusername.Text & "' and userpass='" & Me.txtpwd.Text & "'", con)
dr = cmd.ExecuteReader
If dr.Read Then
Session("username") = Me.txtusername.Text.ToUpper()
Response.Redirect("testPage.aspx", False)
Else
Me.lblmsg.Visible = True
Me.lblmsg.Text = "Wrong Entry"
End If
Catch ex As Exception
Me.lblmsg.Visible = True
Me.lblmsg.Text = ex.ToString
Finally
con.Close()
End Try
End Sub

Step 2 TestPage :
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Session("username") Is Nothing Then
Response.Redirect("Login.aspx")
End If
End Sub




Responses

Author: badamsreekar    31 Jul 2007Member Level: SilverRating:     Points: 2
if ur using forms authentication...
then
in user control of ur application place a label and write
Label1.Text = "WELCOME...." + Context.User.Identity.Name;


Author: Meena Mehra    31 Jul 2007Member Level: GoldRating:     Points: 2
in ur login page just on page_load event write the code
session.add("login name")=txtloginname.text
and then u can use this session login name to the next open page but do remember that u should always add this code in every page otherwise it will clear the session ok
i hope u understand.
one thing more use the autopostback function otherwise it will print the login name as no of times the page will refresed
bye



Post Reply
You must Sign In to post a response.
Next : with connecting to sqlserver getting error
Previous : regular expression validator
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

Help Desk

Contact Us    Privacy Policy    Terms Of Use