Hi,
I am new to asp.net. So just learning everything step by step.
I have created a login page and now on button click on login, i want the page to redirect it to next page "change password" page.
I have written the code, but its not redirecting to next page.
I will post the code here.
can anyone help me,where I am wrong. I may be wrong as I am new to this language.
Waiting for your help
Thanks
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Public Class Login1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("loginConnectionString").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("select * from log where username =@username and Pass=@password", con)
cmd.Parameters.AddWithValue("@username", TextBox1.Text)
cmd.Parameters.AddWithValue("@password", TextBox2.Text)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
If dt.Rows.Count > 0 Then
Response.Redirect("ChangePassword.aspx")
Else
ClientScript.RegisterStartupScript(Page.[GetType](), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>")
End If
End Sub
End Class
this is my html code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb" Inherits="WebApplication2.Login1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
font-size: medium;
font-family: Dotum;
}
.style2
{
color: #FFFFFF;
background-color: #3333FF;
}
.style3
{
width: 55%;
height: 69px;
margin-top: 33px;
}
.style4
{
width: 152px;
}
.style5
{
width: 190px;
}
</style>
</head>
<body style="height: 226px">
<form id="form1" runat="server">
<div class="style1">
<span class="style2">Login Page<br />
</span>
</div>
<table class="style3">
<tr>
<td class="style4">
UserName</td>
<td class="style5">
<asp:TextBox ID="TextBox1" runat="server" Width="180px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="You must enter Username..!!!"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
Password</td>
<td class="style5">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password" Width="180px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="You must enter the password ...!!"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style5">
<asp:Button ID="Button1" runat="server" BackColor="Blue" ForeColor="White"
Text="Login" Width="100px" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style4">
</td>
<td class="style5">
</td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/Account/Register.aspx">New User Register Here</asp:HyperLink>
</td>
</tr>
</table>
</form>
</body>
</html>