[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
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
Re: click a button and go to.
That was exactly what I needed
Thanks a lot!
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.
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?
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")
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?
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)
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?
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. :afrog:
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!
:) :wave:
Re: click a button and go to.
Actually I don't. I don't watch soccer. :(
Re: click a button and go to.
lolol
So why are you messing with me?! :P
:)
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()
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.
1 Attachment(s)
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
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.
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#...
:)
Re: click a button and go to.
String.Format("{0:dd/MM/yyyy}", e.Row.Cells(6).Text)
1 Attachment(s)
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:
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 :(
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)
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
:P
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. :afrog: