lorena Posted May 23, 2005 Posted May 23, 2005 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. Quote
lorena Posted May 23, 2005 Author Posted May 23, 2005 Figured it out. All I needed to do was set "CausesValidation" on the image buttons to "False" Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.