'delayed rediraction asp.net
so I have a login page and I'm trying to have it say "the user doesn't exist" and have it redirect you to the signup page immediately after showing this message, but my current code simply redirects you without displaying the message. sorry if the message is unclear, its the first time i ever write anything in here:)
ulogin.html page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ulogin.aspx.cs" Inherits="User_ulogin" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style5 {
position: absolute;
top: 62px;
left: 53px;
z-index: 1;
}
.auto-style6 {
position: absolute;
top: 140px;
left: 56px;
z-index: 1;
}
.auto-style7 {
position: absolute;
top: 67px;
left: 279px;
z-index: 1;
width: 289px;
}
.auto-style8 {
position: absolute;
top: 141px;
left: 304px;
z-index: 1;
width: 295px;
}
.auto-style9 {
position: absolute;
top: 207px;
left: 219px;
z-index: 1;
}
.auto-style11 {
position: absolute;
top: 277px;
left: 10px;
z-index: 1;
width: 256px;
}
.auto-style12 {
position: absolute;
top: 16px;
left: 244px;
z-index: 1;
}
</style>
</head>
<body style="z-index: 1; width: 1490px; height: 16px; position: absolute; top: 0px; left: 0px">
<form id="form1" runat="server">
<div style="width: 1400px; margin: 0 auto;">
<asp:Label ID="Label2" runat="server" CssClass="auto-style5" Text="username:" Font-Size="18pt" Font-Bold="True"></asp:Label>
<asp:Label ID="Label3" runat="server" CssClass="auto-style6" Text="password:" Font-Size="18pt" Font-Bold="True"></asp:Label>
<asp:TextBox ID="txtuser" runat="server" CssClass="auto-style7" BorderColor="Black" OnTextChanged="txtuser_TextChanged"></asp:TextBox>
<asp:TextBox ID="txtpass" runat="server" CssClass="auto-style8" BorderColor="Black" OnTextChanged="txtpass_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" CssClass="auto-style9" OnClick="Button1_Click" Text="connect now" BackColor="Azure" Font-Size="16pt" BorderColor="Black" />
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="auto-style11" Font-Size="14pt" Font-Underline="True">lost your password? reset it now</asp:HyperLink>
**<asp:Label ID="lblsucc" runat="server" style="z-index: 1; left: 746px; top: 97px; position: absolute" Text="user dont exist" Visible="False"></asp:Label>**
<asp:Label ID="Label4" runat="server" CssClass="auto-style12" Font-Size="XX-Large" Text="Sign Now"></asp:Label>
</div>
</form>
</body>
</html>
ulogin.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class User_ulogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblsucc.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
users user = new users();
admin adn = new admin(txtuser.Text, txtpass.Text);
user.User_Name = txtuser.Text;
user.Pass = txtpass.Text;
if (user.login(user))
{
Session["user"] = txtuser.Text;
Response.Redirect("homepage.aspx");
}
else
{
lblsucc.Visible = true;
}
if(user.ifexist(user))
Response.Redirect("uregister.aspx");
}
protected void txtuser_TextChanged(object sender, EventArgs e)
{
}
protected void txtpass_TextChanged(object sender, EventArgs e)
{
}
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
Response.Redirect("homepage.aspx");
}
}
'''
the relevant classes codes:
''' public bool login(users us)
{
DataSet dsUser = new DataSet();
string stuser = "SELECT tblUsers.User_Name, tblUsers.User_Password FROM tblUsers WHERE(((tblUsers.User_Password) = '" + us.user_Name + "')AND((tblUsers.User_Password) = '" + us.Pass + "')); ";
dsUser = sql.chkData(stuser);
if (dsUser.Tables[0].Rows.Count > 0)
{
return true;
}
else return false;
}'''
'''public bool ifexist(users user)
{
bool chk = false;
DataSet dsUser = new DataSet();
string stuser = "SELECT tblUsers.User_Name FROM tblUsers WHERE(((tblUsers.User_Name) ='" + user.User_Name + "'));";
dsUser = sql.chkData(stuser);
if (dsUser.Tables[0].Rows.Count > 0)
chk = true;
return chk;
}'''
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
