Results 1 to 24 of 24

Thread: [RESOLVED] click a button and go to.

  1. #1

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Resolved [RESOLVED] click a button and go to.

    I have 2 asp pages.

    the first page is default.aspx.vb, and the second is userpage.aspx.vb

    In the first one, I have a login system.
    If the login is correct, it redirect the user to userpage.aspx.vb

    If the login is incorrect, it shows a msgbox saying "go away" and stays in default.aspx.vb.

    My code so far:
    Code:
       
    Protected Sub cmdLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    
                  Dim customers As Northwind.CustomersDataTable = customersAdapter.GetLogin(txtUsername.Text, txtPassword.Text)
    
                  If customers.Count = 1 Then
    ---------- Go to userpage.aspx.vb -------------
                  Else
     
                      MsgBox("Go away!", MsgBoxStyle.Critical, "You aren't registred!")
       
                  End If
     End Sub

  2. #2
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: click a button and go to.

    I think you are looking for response.redirect

    Code:
    If customers.Count = 1 Then
            response.redirect("userpage.aspx")
    Else
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  3. #3

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    That was exactly what I needed

    Thanks a lot!

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    Your login is still insecure though. Anyone could simply go straight to userpage.aspx.

    You should create a session variable if the customer exists, and check for the value of this session variable in userpage.aspx.

  5. #5

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    hello mendhak!

    yes I'm using that I´ve searched for session variables and came up with this:

    Code:
    Dim customers As Northwind.CustomersDataTable = customersAdapter.GetLogin(txtUsername.Text, txtPassword.Text)
    
                  If customers.Count = 1 Then
                         response.redirect("userpage.aspx")
                         me.session("test") = customers(0).customerID
                  Else
     
                      MsgBox("Go away!", MsgBoxStyle.Critical, "You aren't registred!")
       
                  End If
    
    
    In Page userpage.aspx:
    
    Private Function EvaluateValue() As String
            If Session("test") Is Nothing Then
                Return "Empty"
            Else
                Return Session("test").ToString()
            End If
    End Function
    What do you think of this?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    It won't work. First you redirect, then attempt to set a session. Response.Redirect essentially stops page execution, so the session shouldn't get set. Set the session first, then redirect.

    me.session("test") = customers(0).customerID
    response.redirect("userpage.aspx")

  7. #7

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    Hello again mendhak!

    Yes, again you're right! Now it's working.

    So do you think this is secure?

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    Your basic login concept looks fine. But, I would like to see the code for

    customersAdapter.GetLogin(txtUsername.Text, txtPassword.Text)

  9. #9

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    The code for Getlogin is a query with this SQL code:

    SELECT Id_Client, [Password]
    FROM LoginTable
    WHERE (Username = ?) AND ([Password] = ?)

    The Logintable is a table with 3 fields: Id_client, username and password.

    the ID_client is a foreign key to user's table.

    so what do you think?

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    I think that FC Porto couldn't win against a group of doddering grandmothers. :P

    Oh and your setup seems fine.

  11. #11

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    bahh! And you think that because...

    Oh I see, you don't know players like Ricardo Quaresma, Pepe, Adriano, Helton, Raul Meireles, Anderson, Lucho Gonzales, Lisandro Lopez, Postiga... and so on...

    lol

    ok thanks!

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    Actually I don't. I don't watch soccer.

  13. #13

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    lolol
    So why are you messing with me?! :P

  14. #14

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    By the way, Can you hlep me with another thing?

    I have a gridview that is binded with a table adapter and works fine except with the dates!
    For example, in CreationDate the field apears like this:

    22/03/06 - 00:00:00

    This Creation date is a field of an access database. This field is Date/Time but in format it is Abreviate Date.

    What Can I do to take the time off?

    My code:
    Code:
    Dim ServicoAdapter As New GestFacturasTableAdapters.ServicosClienteTableAdapter
    Dim rsSecl As GestFacturas.ServicosClienteDataTable = ServicoAdapter.GetServicosdoCliente(userID)
    
    GridView1.DataSource = rsSecl        
    GridView1.DataBind()
    Last edited by achor; Apr 11th, 2007 at 10:33 AM.

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    Handle the Gridview's RowDataBound event. You can access all the cells of each row everytime the event is raised. In it, you can handle the value displayed in the cell that contains the date, and format it using String.Format()

    String.Format takes format specifiers, a list of which is here.

    I mess with you because it's fun to prod soccer fans.

  16. #16

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    Hello Mendhak!

    Listen I've searched for rowdatabound and I developed this code:
    Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            e.Row.Cells(6).Text = Format(e.Row.Cells(2).Text, "DD/MM/YYYY")
    End Sub
    You can see in the Attachment the result...

    It was not what I expected. The collumn nº3 is also a date collumn.

    Note that it also changed the title of the collumn
    Attached Images Attached Images  

  17. #17
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    That's because your format is wrong.

    DD/MM/YYYY would show up as it is.

    Look at the link I gave you

    http://blog.stevex.net/index.php/str...ing-in-csharp/

    You can use 'd'.

    Also, use String.Format instead of Format(), I'm not sure if that's defaulting to the String class' method call.

  18. #18

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    Hello again Mendhak!

    I tried this:
    Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            If e.Row.Cells(6).Text <> "Dt Inicio" Then
                e.Row.Cells(6).Text = String.Format("{d}", e.Row.Cells(6).Text)
            End If
        End Sub
    "Dt Inicio" is the name of the collumn.

    The result is:

    System.FormatException was unhandled by user code.

    I develop code in vb. I wonder if this String.format is only for C#...


  19. #19
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    String.Format("{0:dd/MM/yyyy}", e.Row.Cells(6).Text)

  20. #20

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Unhappy Re: click a button and go to.

    hello mendhak,

    weekend is off, time to work again

    This still isn't working... I don't know what to do next...

    Code:
     Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            If e.Row.Cells(6).Text <> "Dt Inicio" Then
                e.Row.Cells(6).Text = String.Format("{0:dd/MM/yyyy}", e.Row.Cells(6).Text)
            End If
            If e.Row.Cells(7).Text <> "Dt Expira" Then
                e.Row.Cells(7).Text = String.Format("{0:dd/MM/yyyy}", e.Row.Cells(7).Text)
            End If
        End Sub
    The result is in the attachment:
    Attached Images Attached Images  

  21. #21
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: click a button and go to.

    Just as a test, try replacing

    e.Row.Cells(6).Text = String.Format("{0:dd/MM/yyyy}", e.Row.Cells(6).Text)

    with

    e.Row.Cells(6).Text = String.Format("{0:dd/MM/yyyy}", DateTime.Now)

    To see if it works even for that. Because it did work for me. If it works with DateTime.Now, then we may need to look at string parsing

  22. #22

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    yes you're right, with datetime.now it works perfectly

    I have an idea: what is the function in asp.net vb that is used to cut strings?

    In vb6 I would use this:

    e.Row.Cells(6).Text = left(e.Row.Cells(6).Text , 10)

  23. #23

    Thread Starter
    Lively Member achor's Avatar
    Join Date
    May 2006
    Location
    Porto
    Posts
    123

    Re: click a button and go to.

    I GOT IT !!!!!!!


    it works


    I belive is all for this subject,

    Mendhak thank you for everything!

    And Remember, FC Porto is the best clube in the world!

    :P

  24. #24
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] click a button and go to.

    Glad to know, finally.

    I will try to remember that about FC Porto. For me, the best club in the world is one of those used by the Neanderthals to beat their enemies to death.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width