Keeping subs seperate

Discussion in 'ASP.NET / ASP.NET Core' started by annbransom, Aug 19, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I need help keeping my subs seperate. I have a couple of pages where I have registration or sign-up forms. I also want my member login on every page though. However, if someone tries to login then it sets off the validation on the other form and vice versa. I tried changing the sub from protected to private, but obviously that is not how you do it. This newbie needs some help. The code below is an example. Any help would be greatly appreciated.




    Imports System.Data.OleDb


    Imports System.Data


    Imports System.Data.SqlClient


    Imports system.IO


    Partial Class NewMember


    Inherits System.Web.UI.Page


    Dim dbConn As String = "Data Source=mssql09.discountasp.net;Initial Catalog=DB_261536_annbransom;Persist Security Info=True;User ID=DB_261536_annbransom_user;Password="


    Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRegister.Click


    Dim sqlConn As SqlConnection = New SqlConnection(dbConn)


    Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand()


    Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter


    Dim dt As New DataTable


    With sqlCmd


    .Connection = sqlConn


    .CommandType = CommandType.Text


    .CommandText = "Select KidsKlub_Groups.GroupID from KidsKlub_Groups WHERE GroupID = '" & GroupIDTextBox.Text & "'"


    End With


    sqlConn.Open()


    sqlAdapter.SelectCommand = sqlCmd


    sqlAdapter.Fill(dt)


    sqlConn.Close()


    If dt.Rows.Count = 0 Then


    lblGroupID.Text = "You have entered an invalid group number"


    Else


    If dt.Rows.Count = 1 Then


    dt.Clear()


    With sqlCmd


    .Connection = sqlConn


    .CommandType = CommandType.Text


    .CommandText = "Select * from KidsKlub_Members WHERE username = '" & usernameTextBox.Text & "'"


    End With


    sqlConn.Open()


    sqlAdapter.SelectCommand = sqlCmd


    sqlAdapter.Fill(dt)


    sqlConn.Close()


    If dt.Rows.Count = 0 Then


    Dim FName As String


    FName = FirstNameTextBox.Text


    FName = Replace(FName, "'", "''")


    Dim LName As String


    LName = LastNameTextBox.Text


    LName = Replace(LName, "'", "''")


    With sqlCmd


    .Connection = sqlConn


    .CommandType = CommandType.Text


    .CommandText = "Insert into KidsKlub_Members (GroupID, FirstName, LastName, Email, username, password) values ('" & GroupIDTextBox.Text & "', '" & FName & "', '" & LName & "', '" & EmailTextBox.Text & "', '" & usernameTextBox.Text & "', '" & passwordTextBox.Text & "')"


    .Connection.Open()


    .ExecuteNonQuery()


    .Connection.Close()


    End With


    Response.Redirect("NewRegLogin.aspx")


    Else


    If dt.Rows.Count = 1 Then


    lblUsername.Visible = True


    lblUsername.Text = "The username you have entered is already taken. Please select a different username."


    End If


    End If


    End If


    End If


    End Sub


    Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click


    Dim sqlConn As SqlConnection = New SqlConnection(dbConn)


    Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand()


    Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter


    Dim dt As New DataTable


    Dim UName As String


    Dim Pass As String


    UName = Username.Text


    Pass = Password.Text


    With sqlCmd


    .Connection = sqlConn


    .CommandType = CommandType.Text


    .CommandText = "Select * from KidsKlub_Members, KidsKlub_Groups WHERE Username = '" & UName & "' AND Password = '" & Pass & "' AND KidsKlub_Members.GroupID = KidsKlub_Groups.GroupID"


    End With


    sqlConn.Open()


    sqlAdapter.SelectCommand = sqlCmd


    sqlAdapter.Fill(dt)


    sqlConn.Close()





    If dt.Rows.Count = 0 Then


    lblLogin.Visible = True


    Exit Sub


    Else


    If dt.Rows.Count <> 0 Then


    Session("level") = dt.Rows(0).Item("mLevel")


    Session("name") = dt.Rows(0).Item("FirstName") &amp; " " &amp; dt.Rows(0).Item("LastName")


    Session("logger") = True


    Session("PassID") = dt.Rows(0).Item("MemberID")


    Session("GrpID") = dt.Rows(0).Item("GroupID")


    Session("Capt") = dt.Rows(0).Item("GroupCaption")


    Response.Redirect("welcome.aspx")


    End If


    End If


    End Sub


    End Class
     
  2. It seems that you have multiple sections within your page and you dont want to validate one when the focus is on the other.Well assuming you are working on 2.0 Framework,you could do this using the validationgroup peoprty within your validators to group them together so that only a specific group validation occurs at a time.This is not available in the 1.1 Framework.Hope this helps[​IMG] !!!

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page