473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Login program failure

Hi,

I'm workin on a small Login page/program with asp.net. It uses an MS-Access
database that looks like this:
USERID | NAME | PASSWORD
_________________________________
1 | John | hello
2 | Paul | hello2

I don't understand why it doesn't work. I think i'm doing something wrong
with the client/server side code.

I use WebMatrix for this. The code looks like this:

dim Conn as OleDbConnection
dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\MyDb.mdb"
dim SQL as String="Select NAME, USERID from USERS"
dim dtrUsers as OleDbDataReader
dim cmdSelectUser as OleDbCommand
dim sPassWord as string

Sub Page_Load
if not IsPostBack then
Conn = New OleDbConnection (ConnString)
SQL = "Select NAME, USERID from USERS"
cmdSelectUser = New OleDbCommand (SQL, Conn)
Conn.Open()
dtrUsers = cmdSelectUser.ExecuteReader()
drpUsers.DataSource = dtrUsers
drpUsers.DataTextField = "NAME"
drpUsers.DataValueField = "USERID"
drpUsers.DataBind()
drpUsers.Items.Insert(0, New ListItem("`Select
Name...", -1))
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select PASSWORD from USERS where USERID = " & iUser
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
do while dtrUsers.Read()
sPassword= dtrUsers("PASSWORD")
Loop
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub btnLogIn_Click(sender As Object, e As EventArgs)
If sPassword = txtPassWord.text then
lblStatus.Text = "OK"
else
lblStatus.Text = "NOT OK"
end if
End Sub

The interface looks like this:

<form runat="server">
<asp:DropDownList id="drpUsers" runat="server"
OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
Width="141px"></asp:DropDownList>
<br />
<asp:TextBox id="txtPassWord" runat="server"
AutoPostBack="True"></asp:TextBox>
<br />
<asp:Button id="btnLogIn" onclick="btnLogIn_Click" runat="server"
Text="Verder"></asp:Button>
<br />
<asp:Label id="lblStatus" runat="server">lblStatus</asp:Label>
</form>
Nov 18 '05 #1
7 1528
Your sPassword variable will be blank. When the page loads, the
dropdownlist is populated, the user selects his or her username, the page
posts back to itself and the password is retrieved, but you don't store it
anywhere. When the user hits the LogIn button, the page posts back to
itself again, the drpUsers_SelectedIndexChanged method WON'T fire so the
password won't get reset.

Lose the entire drpUsers_SelectedIndexChanged function and don't have the
form postback when a username is selected. Instead, let users select their
username and password, then in btnLogIn_Click do something like:

dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select * from USERS where USERID = " & iUser & " AND Password = '"
& txtPassWord.text & "'"
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
if dtrUsers.Read then
'THE userId and password match, valid user
else
'invalid user
end if
dtrUsers.Close()
Conn.Close()
end
"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:On*************@TK2MSFTNGP09.phx.gbl...
Hi,

I'm workin on a small Login page/program with asp.net. It uses an MS-Access database that looks like this:
USERID | NAME | PASSWORD
_________________________________
1 | John | hello
2 | Paul | hello2

I don't understand why it doesn't work. I think i'm doing something wrong
with the client/server side code.

I use WebMatrix for this. The code looks like this:

dim Conn as OleDbConnection
dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\MyDb.mdb"
dim SQL as String="Select NAME, USERID from USERS"
dim dtrUsers as OleDbDataReader
dim cmdSelectUser as OleDbCommand
dim sPassWord as string

Sub Page_Load
if not IsPostBack then
Conn = New OleDbConnection (ConnString)
SQL = "Select NAME, USERID from USERS"
cmdSelectUser = New OleDbCommand (SQL, Conn)
Conn.Open()
dtrUsers = cmdSelectUser.ExecuteReader()
drpUsers.DataSource = dtrUsers
drpUsers.DataTextField = "NAME"
drpUsers.DataValueField = "USERID"
drpUsers.DataBind()
drpUsers.Items.Insert(0, New ListItem("`Select
Name...", -1))
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select PASSWORD from USERS where USERID = " & iUser
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
do while dtrUsers.Read()
sPassword= dtrUsers("PASSWORD")
Loop
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub btnLogIn_Click(sender As Object, e As EventArgs)
If sPassword = txtPassWord.text then
lblStatus.Text = "OK"
else
lblStatus.Text = "NOT OK"
end if
End Sub

The interface looks like this:

<form runat="server">
<asp:DropDownList id="drpUsers" runat="server"
OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
Width="141px"></asp:DropDownList>
<br />
<asp:TextBox id="txtPassWord" runat="server"
AutoPostBack="True"></asp:TextBox>
<br />
<asp:Button id="btnLogIn" onclick="btnLogIn_Click" runat="server"
Text="Verder"></asp:Button>
<br />
<asp:Label id="lblStatus" runat="server">lblStatus</asp:Label>
</form>

Nov 18 '05 #2
Hi Karl,

Works great, thanx a lot, except why do i have to click twice the Login
Button?

thanx Cemal

"Karl" <none> schreef in bericht
news:Ox**************@tk2msftngp13.phx.gbl...
Your sPassword variable will be blank. When the page loads, the
dropdownlist is populated, the user selects his or her username, the page
posts back to itself and the password is retrieved, but you don't store it
anywhere. When the user hits the LogIn button, the page posts back to
itself again, the drpUsers_SelectedIndexChanged method WON'T fire so the
password won't get reset.

Lose the entire drpUsers_SelectedIndexChanged function and don't have the
form postback when a username is selected. Instead, let users select their username and password, then in btnLogIn_Click do something like:

dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select * from USERS where USERID = " & iUser & " AND Password = '" & txtPassWord.text & "'"
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
if dtrUsers.Read then
'THE userId and password match, valid user
else
'invalid user
end if
dtrUsers.Close()
Conn.Close()
end
"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:On*************@TK2MSFTNGP09.phx.gbl...
Hi,

I'm workin on a small Login page/program with asp.net. It uses an

MS-Access
database that looks like this:
USERID | NAME | PASSWORD
_________________________________
1 | John | hello
2 | Paul | hello2

I don't understand why it doesn't work. I think i'm doing something wrong with the client/server side code.

I use WebMatrix for this. The code looks like this:

dim Conn as OleDbConnection
dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\MyDb.mdb"
dim SQL as String="Select NAME, USERID from USERS"
dim dtrUsers as OleDbDataReader
dim cmdSelectUser as OleDbCommand
dim sPassWord as string

Sub Page_Load
if not IsPostBack then
Conn = New OleDbConnection (ConnString)
SQL = "Select NAME, USERID from USERS"
cmdSelectUser = New OleDbCommand (SQL, Conn)
Conn.Open()
dtrUsers = cmdSelectUser.ExecuteReader()
drpUsers.DataSource = dtrUsers
drpUsers.DataTextField = "NAME"
drpUsers.DataValueField = "USERID"
drpUsers.DataBind()
drpUsers.Items.Insert(0, New ListItem("`Select
Name...", -1))
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select PASSWORD from USERS where USERID = " & iUser
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
do while dtrUsers.Read()
sPassword= dtrUsers("PASSWORD")
Loop
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub btnLogIn_Click(sender As Object, e As EventArgs)
If sPassword = txtPassWord.text then
lblStatus.Text = "OK"
else
lblStatus.Text = "NOT OK"
end if
End Sub

The interface looks like this:

<form runat="server">
<asp:DropDownList id="drpUsers" runat="server"
OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
Width="141px"></asp:DropDownList>
<br />
<asp:TextBox id="txtPassWord" runat="server"
AutoPostBack="True"></asp:TextBox>
<br />
<asp:Button id="btnLogIn" onclick="btnLogIn_Click" runat="server" Text="Verder"></asp:Button>
<br />
<asp:Label id="lblStatus" runat="server">lblStatus</asp:Label>
</form>


Nov 18 '05 #3
You are saying nothing happens when you click the button the first time? or
does it postback and give an invalid user but work the 2nd time by simply
clicking again?

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
Hi Karl,

Works great, thanx a lot, except why do i have to click twice the Login
Button?

thanx Cemal

"Karl" <none> schreef in bericht
news:Ox**************@tk2msftngp13.phx.gbl...
Your sPassword variable will be blank. When the page loads, the
dropdownlist is populated, the user selects his or her username, the page
posts back to itself and the password is retrieved, but you don't store it anywhere. When the user hits the LogIn button, the page posts back to
itself again, the drpUsers_SelectedIndexChanged method WON'T fire so the
password won't get reset.

Lose the entire drpUsers_SelectedIndexChanged function and don't have the form postback when a username is selected. Instead, let users select

their
username and password, then in btnLogIn_Click do something like:

dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select * from USERS where USERID = " & iUser & " AND Password =

'"
& txtPassWord.text & "'"
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
if dtrUsers.Read then
'THE userId and password match, valid user
else
'invalid user
end if
dtrUsers.Close()
Conn.Close()
end
"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:On*************@TK2MSFTNGP09.phx.gbl...
Hi,

I'm workin on a small Login page/program with asp.net. It uses an

MS-Access
database that looks like this:
USERID | NAME | PASSWORD
_________________________________
1 | John | hello
2 | Paul | hello2

I don't understand why it doesn't work. I think i'm doing something

wrong with the client/server side code.

I use WebMatrix for this. The code looks like this:

dim Conn as OleDbConnection
dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\MyDb.mdb"
dim SQL as String="Select NAME, USERID from USERS"
dim dtrUsers as OleDbDataReader
dim cmdSelectUser as OleDbCommand
dim sPassWord as string

Sub Page_Load
if not IsPostBack then
Conn = New OleDbConnection (ConnString)
SQL = "Select NAME, USERID from USERS"
cmdSelectUser = New OleDbCommand (SQL, Conn)
Conn.Open()
dtrUsers = cmdSelectUser.ExecuteReader()
drpUsers.DataSource = dtrUsers
drpUsers.DataTextField = "NAME"
drpUsers.DataValueField = "USERID"
drpUsers.DataBind()
drpUsers.Items.Insert(0, New ListItem("`Select
Name...", -1))
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select PASSWORD from USERS where USERID = " & iUser
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
do while dtrUsers.Read()
sPassword= dtrUsers("PASSWORD")
Loop
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub btnLogIn_Click(sender As Object, e As EventArgs)
If sPassword = txtPassWord.text then
lblStatus.Text = "OK"
else
lblStatus.Text = "NOT OK"
end if
End Sub

The interface looks like this:

<form runat="server">
<asp:DropDownList id="drpUsers" runat="server"
OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
Width="141px"></asp:DropDownList>
<br />
<asp:TextBox id="txtPassWord" runat="server"
AutoPostBack="True"></asp:TextBox>
<br />
<asp:Button id="btnLogIn" onclick="btnLogIn_Click" runat="server" Text="Verder"></asp:Button>
<br />
<asp:Label id="lblStatus" runat="server">lblStatus</asp:Label>
</form>



Nov 18 '05 #4
The first time I click nothing happens. The second time it works. I don't
understand why that is. I can pass the code if you want.

"Karl" <none> schreef in bericht
news:O7**************@TK2MSFTNGP12.phx.gbl...
You are saying nothing happens when you click the button the first time? or does it postback and give an invalid user but work the 2nd time by simply
clicking again?

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
Hi Karl,

Works great, thanx a lot, except why do i have to click twice the Login
Button?

thanx Cemal

"Karl" <none> schreef in bericht
news:Ox**************@tk2msftngp13.phx.gbl...
Your sPassword variable will be blank. When the page loads, the
dropdownlist is populated, the user selects his or her username, the page posts back to itself and the password is retrieved, but you don't store
it
anywhere. When the user hits the LogIn button, the page posts back to
itself again, the drpUsers_SelectedIndexChanged method WON'T fire so
the password won't get reset.

Lose the entire drpUsers_SelectedIndexChanged function and don't have the form postback when a username is selected. Instead, let users select

their
username and password, then in btnLogIn_Click do something like:

dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select * from USERS where USERID = " & iUser & " AND Password = '"
& txtPassWord.text & "'"
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
if dtrUsers.Read then
'THE userId and password match, valid user
else
'invalid user
end if
dtrUsers.Close()
Conn.Close()
end
"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:On*************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I'm workin on a small Login page/program with asp.net. It uses an
MS-Access
> database that looks like this:
> USERID | NAME | PASSWORD
> _________________________________
> 1 | John | hello
> 2 | Paul | hello2
>
> I don't understand why it doesn't work. I think i'm doing something

wrong
> with the client/server side code.
>
> I use WebMatrix for this. The code looks like this:
>
> dim Conn as OleDbConnection
> dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole

DB > Services=-4; Data Source=C:\MyDb.mdb"
> dim SQL as String="Select NAME, USERID from USERS"
> dim dtrUsers as OleDbDataReader
> dim cmdSelectUser as OleDbCommand
> dim sPassWord as string
>
> Sub Page_Load
> if not IsPostBack then
> Conn = New OleDbConnection (ConnString)
> SQL = "Select NAME, USERID from USERS"
> cmdSelectUser = New OleDbCommand (SQL, Conn)
> Conn.Open()
> dtrUsers = cmdSelectUser.ExecuteReader()
> drpUsers.DataSource = dtrUsers
> drpUsers.DataTextField = "NAME"
> drpUsers.DataValueField = "USERID"
> drpUsers.DataBind()
> drpUsers.Items.Insert(0, New ListItem("`Select
> Name...", -1))
> dtrUsers.Close()
> Conn.Close()
> end if
> End Sub
>
> Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
> dim iUser as integer = drpUsers.SelectedItem.Value
> if iUser <> -1 then
> SQL="Select PASSWORD from USERS where USERID = " & iUser
> Conn = New OleDbConnection (ConnString)
> Conn.Open()
> cmdSelectUser = New OleDbCommand (SQL, Conn)
> dtrUsers = cmdSelectUser.ExecuteReader()
> do while dtrUsers.Read()
> sPassword= dtrUsers("PASSWORD")
> Loop
> dtrUsers.Close()
> Conn.Close()
> end if
> End Sub
>
> Sub btnLogIn_Click(sender As Object, e As EventArgs)
> If sPassword = txtPassWord.text then
> lblStatus.Text = "OK"
> else
> lblStatus.Text = "NOT OK"
> end if
> End Sub
>
> The interface looks like this:
>
> <form runat="server">
> <asp:DropDownList id="drpUsers" runat="server"
> OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
> Width="141px"></asp:DropDownList>
> <br />
> <asp:TextBox id="txtPassWord" runat="server"
> AutoPostBack="True"></asp:TextBox>
> <br />
> <asp:Button id="btnLogIn" onclick="btnLogIn_Click"

runat="server"
> Text="Verder"></asp:Button>
> <br />
> <asp:Label id="lblStatus" runat="server">lblStatus</asp:Label> > </form>
>
>



Nov 18 '05 #5
When I click an other button (without any code behind it), it also works.
"Karl" <none> schreef in bericht
news:O7**************@TK2MSFTNGP12.phx.gbl...
You are saying nothing happens when you click the button the first time? or does it postback and give an invalid user but work the 2nd time by simply
clicking again?

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
Hi Karl,

Works great, thanx a lot, except why do i have to click twice the Login
Button?

thanx Cemal

"Karl" <none> schreef in bericht
news:Ox**************@tk2msftngp13.phx.gbl...
Your sPassword variable will be blank. When the page loads, the
dropdownlist is populated, the user selects his or her username, the page posts back to itself and the password is retrieved, but you don't store
it
anywhere. When the user hits the LogIn button, the page posts back to
itself again, the drpUsers_SelectedIndexChanged method WON'T fire so
the password won't get reset.

Lose the entire drpUsers_SelectedIndexChanged function and don't have the form postback when a username is selected. Instead, let users select

their
username and password, then in btnLogIn_Click do something like:

dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select * from USERS where USERID = " & iUser & " AND Password = '"
& txtPassWord.text & "'"
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
if dtrUsers.Read then
'THE userId and password match, valid user
else
'invalid user
end if
dtrUsers.Close()
Conn.Close()
end
"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:On*************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I'm workin on a small Login page/program with asp.net. It uses an
MS-Access
> database that looks like this:
> USERID | NAME | PASSWORD
> _________________________________
> 1 | John | hello
> 2 | Paul | hello2
>
> I don't understand why it doesn't work. I think i'm doing something

wrong
> with the client/server side code.
>
> I use WebMatrix for this. The code looks like this:
>
> dim Conn as OleDbConnection
> dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole

DB > Services=-4; Data Source=C:\MyDb.mdb"
> dim SQL as String="Select NAME, USERID from USERS"
> dim dtrUsers as OleDbDataReader
> dim cmdSelectUser as OleDbCommand
> dim sPassWord as string
>
> Sub Page_Load
> if not IsPostBack then
> Conn = New OleDbConnection (ConnString)
> SQL = "Select NAME, USERID from USERS"
> cmdSelectUser = New OleDbCommand (SQL, Conn)
> Conn.Open()
> dtrUsers = cmdSelectUser.ExecuteReader()
> drpUsers.DataSource = dtrUsers
> drpUsers.DataTextField = "NAME"
> drpUsers.DataValueField = "USERID"
> drpUsers.DataBind()
> drpUsers.Items.Insert(0, New ListItem("`Select
> Name...", -1))
> dtrUsers.Close()
> Conn.Close()
> end if
> End Sub
>
> Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
> dim iUser as integer = drpUsers.SelectedItem.Value
> if iUser <> -1 then
> SQL="Select PASSWORD from USERS where USERID = " & iUser
> Conn = New OleDbConnection (ConnString)
> Conn.Open()
> cmdSelectUser = New OleDbCommand (SQL, Conn)
> dtrUsers = cmdSelectUser.ExecuteReader()
> do while dtrUsers.Read()
> sPassword= dtrUsers("PASSWORD")
> Loop
> dtrUsers.Close()
> Conn.Close()
> end if
> End Sub
>
> Sub btnLogIn_Click(sender As Object, e As EventArgs)
> If sPassword = txtPassWord.text then
> lblStatus.Text = "OK"
> else
> lblStatus.Text = "NOT OK"
> end if
> End Sub
>
> The interface looks like this:
>
> <form runat="server">
> <asp:DropDownList id="drpUsers" runat="server"
> OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
> Width="141px"></asp:DropDownList>
> <br />
> <asp:TextBox id="txtPassWord" runat="server"
> AutoPostBack="True"></asp:TextBox>
> <br />
> <asp:Button id="btnLogIn" onclick="btnLogIn_Click"

runat="server"
> Text="Verder"></asp:Button>
> <br />
> <asp:Label id="lblStatus" runat="server">lblStatus</asp:Label> > </form>
>
>



Nov 18 '05 #6
Code would help..otherwise, if you are able to debug, you should be able to
find the problem fairly easily.

Karl

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
The first time I click nothing happens. The second time it works. I don't
understand why that is. I can pass the code if you want.

"Karl" <none> schreef in bericht
news:O7**************@TK2MSFTNGP12.phx.gbl...
You are saying nothing happens when you click the button the first time? or
does it postback and give an invalid user but work the 2nd time by simply
clicking again?

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
Hi Karl,

Works great, thanx a lot, except why do i have to click twice the Login Button?

thanx Cemal

"Karl" <none> schreef in bericht
news:Ox**************@tk2msftngp13.phx.gbl...
> Your sPassword variable will be blank. When the page loads, the
> dropdownlist is populated, the user selects his or her username, the

page
> posts back to itself and the password is retrieved, but you don't store
it
> anywhere. When the user hits the LogIn button, the page posts back to > itself again, the drpUsers_SelectedIndexChanged method WON'T fire so

the > password won't get reset.
>
> Lose the entire drpUsers_SelectedIndexChanged function and don't have the
> form postback when a username is selected. Instead, let users
select their
> username and password, then in btnLogIn_Click do something like:
>
> dim iUser as integer = drpUsers.SelectedItem.Value
> if iUser <> -1 then
> SQL="Select * from USERS where USERID = " & iUser & " AND Password = '"
> & txtPassWord.text & "'"
> Conn = New OleDbConnection (ConnString)
> Conn.Open()
> cmdSelectUser = New OleDbCommand (SQL, Conn)
> dtrUsers = cmdSelectUser.ExecuteReader()
> if dtrUsers.Read then
> 'THE userId and password match, valid user
> else
> 'invalid user
> end if
> dtrUsers.Close()
> Conn.Close()
> end
>
>
> "Cemal Karademir" <c.*********@zonnet.nl> wrote in message
> news:On*************@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > I'm workin on a small Login page/program with asp.net. It uses an
> MS-Access
> > database that looks like this:
> > USERID | NAME | PASSWORD
> > _________________________________
> > 1 | John | hello
> > 2 | Paul | hello2
> >
> > I don't understand why it doesn't work. I think i'm doing
something wrong
> > with the client/server side code.
> >
> > I use WebMatrix for this. The code looks like this:
> >
> > dim Conn as OleDbConnection
> > dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB > > Services=-4; Data Source=C:\MyDb.mdb"
> > dim SQL as String="Select NAME, USERID from USERS"
> > dim dtrUsers as OleDbDataReader
> > dim cmdSelectUser as OleDbCommand
> > dim sPassWord as string
> >
> > Sub Page_Load
> > if not IsPostBack then
> > Conn = New OleDbConnection (ConnString)
> > SQL = "Select NAME, USERID from USERS"
> > cmdSelectUser = New OleDbCommand (SQL, Conn)
> > Conn.Open()
> > dtrUsers = cmdSelectUser.ExecuteReader()
> > drpUsers.DataSource = dtrUsers
> > drpUsers.DataTextField = "NAME"
> > drpUsers.DataValueField = "USERID"
> > drpUsers.DataBind()
> > drpUsers.Items.Insert(0, New ListItem("`Select
> > Name...", -1))
> > dtrUsers.Close()
> > Conn.Close()
> > end if
> > End Sub
> >
> > Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs)
> > dim iUser as integer = drpUsers.SelectedItem.Value
> > if iUser <> -1 then
> > SQL="Select PASSWORD from USERS where USERID = " &
iUser > > Conn = New OleDbConnection (ConnString)
> > Conn.Open()
> > cmdSelectUser = New OleDbCommand (SQL, Conn)
> > dtrUsers = cmdSelectUser.ExecuteReader()
> > do while dtrUsers.Read()
> > sPassword= dtrUsers("PASSWORD")
> > Loop
> > dtrUsers.Close()
> > Conn.Close()
> > end if
> > End Sub
> >
> > Sub btnLogIn_Click(sender As Object, e As EventArgs)
> > If sPassword = txtPassWord.text then
> > lblStatus.Text = "OK"
> > else
> > lblStatus.Text = "NOT OK"
> > end if
> > End Sub
> >
> > The interface looks like this:
> >
> > <form runat="server">
> > <asp:DropDownList id="drpUsers" runat="server"
> > OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
> > Width="141px"></asp:DropDownList>
> > <br />
> > <asp:TextBox id="txtPassWord" runat="server"
> > AutoPostBack="True"></asp:TextBox>
> > <br />
> > <asp:Button id="btnLogIn" onclick="btnLogIn_Click"
runat="server"
> > Text="Verder"></asp:Button>
> > <br />
> > <asp:Label id="lblStatus"

runat="server">lblStatus</asp:Label> > > </form>
> >
> >
>
>



Nov 18 '05 #7
Here's the code.

When I click btnClose (there is no code behind it) and then btn LogIn it
works. Or I have to click btnLogIn twice. Maybe because the set focus loses?

Thanx, Cemal

<%@ Page Language="VB" Debug="TRUE" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

dim Conn as OleDbConnection
dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\MyDb.mdb"
dim SQL as String="Select NAME, USERID from USERS"
dim dtrUsers as OleDbDataReader
dim cmdSelectUser as OleDbCommand

Sub Page_Load
if Not IsPostBack then
Conn = New OleDbConnection (ConnString)
SQL = "Select NAME, USERID from USERS"
cmdSelectUser = New OleDbCommand (SQL, Conn)
Conn.Open()
dtrUsers = cmdSelectUser.ExecuteReader()
drpUsers.DataSource = dtrUsers
drpUsers.DataTextField = "NAME"
drpUsers.DataValueField = "USERID"
drpUsers.DataBind()
drpUsers.Items.Insert(0, New ListItem("Select Name...", -1))
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub btnLogIn_Click(sender As Object, e As EventArgs)
' I have to click this button twice???
dim iUser as integer = drpUsers.SelectedItem.Value
if iUser <> -1 then
SQL="Select * from USERS where USERID = " & iUser & " AND Password =
'" & txtPassWord.text & "'"
Conn = New OleDbConnection (ConnString)
Conn.Open()
cmdSelectUser = New OleDbCommand (SQL, Conn)
dtrUsers = cmdSelectUser.ExecuteReader()
if dtrUsers.Read then
Response.Redirect("NextPage.aspx")
end if
dtrUsers.Close()
Conn.Close()
end if
End Sub

Sub btnClose_Click(sender As Object, e As EventArgs)
' There is no code !!!
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DropDownList id="drpUsers" runat="server"
Width="141px"></asp:DropDownList>
<br />
<asp:TextBox id="txtPassWord" runat="server"
AutoPostBack="True"></asp:TextBox>
<br />
<asp:Button id="btnLogIn" onclick="btnLogIn_Click" runat="server"
Text="Verder"></asp:Button>
<br />
<asp:Button id="btnClose" onclick="btnClose_Click" runat="server"
Text="Afsluiten"></asp:Button>
<br />
<asp:Label id="lblUser" runat="server">lblUser</asp:Label>
</form>
</body>
</html>

"Karl" <none> schreef in bericht
news:Ol**************@TK2MSFTNGP09.phx.gbl...
Code would help..otherwise, if you are able to debug, you should be able to find the problem fairly easily.

Karl

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
The first time I click nothing happens. The second time it works. I don't
understand why that is. I can pass the code if you want.

"Karl" <none> schreef in bericht
news:O7**************@TK2MSFTNGP12.phx.gbl...
You are saying nothing happens when you click the button the first time?
or
does it postback and give an invalid user but work the 2nd time by simply clicking again?

"Cemal Karademir" <c.*********@zonnet.nl> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
> Hi Karl,
>
> Works great, thanx a lot, except why do i have to click twice the Login > Button?
>
> thanx Cemal
>
> "Karl" <none> schreef in bericht
> news:Ox**************@tk2msftngp13.phx.gbl...
> > Your sPassword variable will be blank. When the page loads, the
> > dropdownlist is populated, the user selects his or her username,
the page
> > posts back to itself and the password is retrieved, but you don't store
it
> > anywhere. When the user hits the LogIn button, the page posts back to > > itself again, the drpUsers_SelectedIndexChanged method WON'T fire
so the
> > password won't get reset.
> >
> > Lose the entire drpUsers_SelectedIndexChanged function and don't

have the
> > form postback when a username is selected. Instead, let users select > their
> > username and password, then in btnLogIn_Click do something like:
> >
> > dim iUser as integer = drpUsers.SelectedItem.Value
> > if iUser <> -1 then
> > SQL="Select * from USERS where USERID = " & iUser & " AND Password
=
> '"
> > & txtPassWord.text & "'"
> > Conn = New OleDbConnection (ConnString)
> > Conn.Open()
> > cmdSelectUser = New OleDbCommand (SQL, Conn)
> > dtrUsers = cmdSelectUser.ExecuteReader()
> > if dtrUsers.Read then
> > 'THE userId and password match, valid user
> > else
> > 'invalid user
> > end if
> > dtrUsers.Close()
> > Conn.Close()
> > end
> >
> >
> > "Cemal Karademir" <c.*********@zonnet.nl> wrote in message
> > news:On*************@TK2MSFTNGP09.phx.gbl...
> > > Hi,
> > >
> > > I'm workin on a small Login page/program with asp.net. It uses

an > > MS-Access
> > > database that looks like this:
> > > USERID | NAME | PASSWORD
> > > _________________________________
> > > 1 | John | hello
> > > 2 | Paul | hello2
> > >
> > > I don't understand why it doesn't work. I think i'm doing

something > wrong
> > > with the client/server side code.
> > >
> > > I use WebMatrix for this. The code looks like this:
> > >
> > > dim Conn as OleDbConnection
> > > dim ConnString as String="Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB
> > > Services=-4; Data Source=C:\MyDb.mdb"
> > > dim SQL as String="Select NAME, USERID from USERS"
> > > dim dtrUsers as OleDbDataReader
> > > dim cmdSelectUser as OleDbCommand
> > > dim sPassWord as string
> > >
> > > Sub Page_Load
> > > if not IsPostBack then
> > > Conn = New OleDbConnection (ConnString)
> > > SQL = "Select NAME, USERID from USERS"
> > > cmdSelectUser = New OleDbCommand (SQL, Conn)
> > > Conn.Open()
> > > dtrUsers = cmdSelectUser.ExecuteReader()
> > > drpUsers.DataSource = dtrUsers
> > > drpUsers.DataTextField = "NAME"
> > > drpUsers.DataValueField = "USERID"
> > > drpUsers.DataBind()
> > > drpUsers.Items.Insert(0, New ListItem("`Select
> > > Name...", -1))
> > > dtrUsers.Close()
> > > Conn.Close()
> > > end if
> > > End Sub
> > >
> > > Sub drpUsers_SelectedIndexChanged(s As Object, e As EventArgs) > > > dim iUser as integer = drpUsers.SelectedItem.Value
> > > if iUser <> -1 then
> > > SQL="Select PASSWORD from USERS where USERID = " &

iUser > > > Conn = New OleDbConnection (ConnString)
> > > Conn.Open()
> > > cmdSelectUser = New OleDbCommand (SQL, Conn)
> > > dtrUsers = cmdSelectUser.ExecuteReader()
> > > do while dtrUsers.Read()
> > > sPassword= dtrUsers("PASSWORD")
> > > Loop
> > > dtrUsers.Close()
> > > Conn.Close()
> > > end if
> > > End Sub
> > >
> > > Sub btnLogIn_Click(sender As Object, e As EventArgs)
> > > If sPassword = txtPassWord.text then
> > > lblStatus.Text = "OK"
> > > else
> > > lblStatus.Text = "NOT OK"
> > > end if
> > > End Sub
> > >
> > > The interface looks like this:
> > >
> > > <form runat="server">
> > > <asp:DropDownList id="drpUsers" runat="server"
> > > OnSelectedIndexChanged="drpUsers_SelectedIndexChan ged"
> > > Width="141px"></asp:DropDownList>
> > > <br />
> > > <asp:TextBox id="txtPassWord" runat="server"
> > > AutoPostBack="True"></asp:TextBox>
> > > <br />
> > > <asp:Button id="btnLogIn" onclick="btnLogIn_Click"
> runat="server"
> > > Text="Verder"></asp:Button>
> > > <br />
> > > <asp:Label id="lblStatus"

runat="server">lblStatus</asp:Label>
> > > </form>
> > >
> > >
> >
> >
>
>



Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pitaridis Aristotelis | last post by:
I tried to make a login page, and store all the required information so that the user will not be able to go directly to a non-authorized page, but the whole idea was a failure. Does anybody know...
3
by: Jim Peter | last post by:
Hello , this is my first posting in this group. I am running SQL server 2000 on my windows 2000 server box. I use it for my Siebel database. When ever I launch Query Analyzer and chose SQL Server...
1
by: Twitch | last post by:
Turns out I can only use Windows Authentication for the website. So I ask again. Is there a way or method of knowing when a "Window Authentication" logon fails? Maybe a system exception I can...
5
by: R.A.M. | last post by:
Hello Could you help a beginner with login implementation using asp:Login (.NET 2.0). I have in Web.config: <authentication mode="Forms"> <forms name="Demo.NET" loginUrl="Default.aspx" />...
12
by: Michael | last post by:
Please Help me. I've got a .Net 2003 program that attaches to a SQL Server machine and I'm getting the above error when a user tries to log in. The SQL server is setup to use Windows Auth. and I...
2
by: Shakun | last post by:
Hi All, This is my 1st posting to this group. Can any1 help me with the "Remember Me" which is there in a login form. Im pasting the code below. Im not able to set a cookie.. Thanks, Shakun...
2
by: dubdave | last post by:
Hi I wrote a very basic login script which acesses a mySQL database, like this:- <?php // compares values entered in login page form with mySQL database, and then directs either to...
0
by: kuldeep singh sethi | last post by:
Hi All, I am facing a problem from many days. and need to help me. i am a local machine user. I am developing a site in which login page is as start page. and there is sql server as database. so...
0
by: jobs | last post by:
This code works at setting my login failure message, but does not set the color for some reason. Protected Overrides Sub OnLoad(ByVal e As EventArgs) If IsPostBack Then If Login.FailureText <""...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.