Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a small asp.net app that loads a login page with two textboxes for username and password and a login button. Each textbox has a RequiredFieldvalidator and I use the Page.IsValid for the OnClick event of the Login button.

I also have two hyperlinks on the page so that users can go back to non-login pages.

My problem is that the RequiredFieldvalidator events fire when either hyperlink is clicked and keep the hyperlinks from allowing users to navigate off of the page.

<script language="VB" runat="server">

'Code for the login button

Sub Login_Click(Src As Object, E As EventArgs)

If Page.IsValid Then

Dim strUN as string = txtUN.text

Dim strPW as string = txtPwd.text

Dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & server.mappath("DB/sf.mdb") & ";"

Dim Conn as New OLEDBConnection(strConn)

Conn.Open()

Dim strSQL as string = "SELECT * FROM info WHERE un = '~' and pwd= 'Val1'"

strSQL = Replace(strSQL,"~", strUN)

strSQL = Replace(strSQL,"Val1", strPW)

Dim Cmd as New OLEDBCommand(strSQL,Conn)

 

'Create a datareader, connection object

Dim Dr as OLEDBDataReader = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

 

'Get the first row and check the password.

If Dr.Read() then

If Dr("Pwd").ToString = txtPwd.text and DR("UN").ToString=txtUN.text Then

FormsAuthentication.RedirectFromLoginPage(txtUN.Text, false)

Else

lblLoginMsg.text = "Invalid login attempt."

End If

Else

lblLoginMsg.text = "Login name or Password not found."

End If

Dr.Close

End If

End Sub

Sub tds_img_OnClick(Sender As Object, E As ImageClickEventArgs)

If not Page.IsValid then

FormsAuthentication.SignOut()

Response.Redirect ("http://www.homepage.com")

End If

End Sub

Sub sup_img_OnClick(Sender As Object, E As ImageClickEventArgs)

FormsAuthentication.SignOut()

Response.Redirect ("http://www.homepage.com/sup/welcome.htm")

End Sub

</script>

Is there someway to get around this? Some Page event that I am missing?

Thanks in advance for any help.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...