Reputation: 375
I strated building a site in HTML and SQL. Here is the code: Login.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Default2" %>
<!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>login</title>
<link href="main.css" rel="Stylesheet" type="text/css" />
</head>
<body dir="ltr">
<iframe src="menu.html" width="670px" height="170px" frameBorder="0" style="position:absolute;right:23em">
</iframe>
<img src="design\login2.jpg" height="300px" id="frc">
<form id="lgin" runat="server">
<table class="regtext">
<tr class="sec">
<td>username</td>
<td><input type="text" id="userName" name="userName" class="filld" </td>
</tr>
<tr>
<td>password</td>
<td><input type="password" id="pass" name="pass" class="filld" </td>
</tr>
<input type="submit" class="btn btn-large btn-warning" id="legbtn" value="login" />
</table>
<%=status %>
</form>
</body>
</html>
the code for server side (C#): Login.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 login : System.Web.UI.Page
{
public string status = "";
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string userName = Request.Form["userName"];
string password = Request.Form["pass"];
string sql = string.Format("SELECT * FROM Users WHERE userName='{0}' ", userName);
sql += string.Format("AND password='{0}'", password);
if (MyAdoHelper.IsExist("Database.mdf", sql))
{
Session["userName"] = userName;
sql = string.Format("SELECT * FROM Users WHERE userName='{0}' ", userName);
sql += string.Format("AND admin='{0}'", true);
if (MyAdoHelper.IsExist("Database.mdf", sql))
{
Session["admin"] = "admin";
Response.Redirect("Admin.aspx");
}
else
Response.Redirect("ForRegistered.aspx");
}
else
status = "error!";
}
}
}
The error is "status does not exist in current context". Where is the problem?
Upvotes: 0
Views: 91
Reputation: 585
Your page inherits Default2 and not login. Change the inherits in the page directive on your aspx page to inherit the correct class and you should be in better shape.
Upvotes: 2