| | |
Need help on ASP.NET (Login Page)
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
I don't know why it kept appear this error: The name 'LogoutBT' does not exist in the current context.
All my textboxes and buttons do not exist in the current context
Please help me. Thanks.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
DBConnect Connect = new DBConnect();
protected void Page_Load(object sender, EventArgs e)
{
if ((string)Session["sFlag"] == "T")
{
LoggedIn();
}
else
{
Session["sName"] = null;
Session["sUserName"] = null;
Session["sAddress"] = null;
Session["sCoContact"] = null;
Session["sPIC"] = null;
Session["sPICContact"] = null;
Session["sFlag"] = "F";
passwordTB.Visible = true;
passwordTB.Text = "";
usernameTB.Visible = true;
usernameTB.Text = "";
usernameTB.Text = "UserID:";
LogoutBT.Visible = false;
LoginBT.Visible = true;
}
}
protected void LoginBT_Click(object sender, EventArgs e)
{
if (usernameTB.Text != "")
{
if (passwordTB.Text != "")
{
OleDbConnection mdb = new OleDbConnection();
OleDbCommand cmd;
OleDbDataReader rdr;
Connect.DBConnection(mdb);
mdb.Open();
string SQLinfo = "SELECT * FROM Customers WHERE cUserName = '" +
usernameTB.Text.ToUpper() + "'";
string SQLlog = "INSERT INTO Log (lName,lLogIn) " +
"VALUES (@UserName, @Date)";
cmd = new OleDbCommand(SQLinfo, mdb);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
if (passwordTB.Text == (string)rdr["cPassword"])
{
Session["sName"] = rdr["cName"];
Session["sUserName"] = rdr["cUserName"];
Session["sAddress"] = rdr["cCoAddress"];
Session["sCoContact"] = rdr["cCoContact"];
Session["sPIC"] = rdr["cPersonInCharge"];
Session["sPICContact"] = rdr["cPICContact"];
Session["sEmail"] = rdr["cEmail"];
Session["sStatus"] = rdr["cStatus"];
Session["sFlag"] = "T";
rdr.Close();
cmd = new OleDbCommand(SQLlog, mdb);
cmd.Parameters.Add("@UserName", OleDbType.Char).Value = (string)Session["sCoName"];
cmd.Parameters.Add("@Date", OleDbType.Date).Value = DateTime.Now;
cmd.ExecuteNonQuery();
mdb.Close();
LoggedIn();
break;
}
else
{
rdr.Close();
mdb.Close();
usernameTB.Text = "";
passwordTB.Text = "";
Response.Write("<script>alert('Error signing in')</script>");
break;
}
}
mdb.Close();
}
else
{
passwordTB.Focus();
Response.Write("<script>alert('Please enter your password')</script>");
}
}
else
{
usernameTB.Focus();
Response.Write("<script>alert('Please enter your UserID')</script>");
}
}
protected void LogoutBT_Click(object sender, EventArgs e)
{
OleDbConnection mdb = new OleDbConnection();
OleDbCommand cmd;
Connect.DBConnection(mdb);
string SQLlog = "UPDATE Log SET lLogOut = @Date WHERE lCoName = @Name";
cmd = new OleDbCommand(SQLlog, mdb);
cmd.Parameters.Add("@Date", OleDbType.Date).Value = DateTime.Now;
cmd.Parameters.Add("@Name", OleDbType.Char).Value = (string)Session["sUserName"];
mdb.Open();
cmd.ExecuteNonQuery();
mdb.Close();
LoggedOut();
}
protected void LoggedOut()
{
Session["sName"] = null;
Session["sUserName"] = null;
Session["sAddress"] = null;
Session["sCoContact"] = null;
Session["sPIC"] = null;
Session["sPICContact"] = null;
Session["sFlag"] = "F";
passwordTB.Visible = true;
passwordTB.Text = "";
usernameTB.Visible = true;
usernameTB.Text = "";
usernameTB.Text = "UserID:";
LogoutBT.Visible = false;
LoginBT.Visible = true;
Response.Redirect("OnlineRVform.aspx");
}
protected void LoggedIn()
{
passwordTB.Visible = false;
passwordTB.Text = "";
usernameTB.Visible = false;
usernameTB.Text = "";
usernameTB.Text = (string)Session["sPIC"];
LogoutBT.Visible = true;
LoginBT.Visible = false;
}
All my textboxes and buttons do not exist in the current context
Please help me. Thanks.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
DBConnect Connect = new DBConnect();
protected void Page_Load(object sender, EventArgs e)
{
if ((string)Session["sFlag"] == "T")
{
LoggedIn();
}
else
{
Session["sName"] = null;
Session["sUserName"] = null;
Session["sAddress"] = null;
Session["sCoContact"] = null;
Session["sPIC"] = null;
Session["sPICContact"] = null;
Session["sFlag"] = "F";
passwordTB.Visible = true;
passwordTB.Text = "";
usernameTB.Visible = true;
usernameTB.Text = "";
usernameTB.Text = "UserID:";
LogoutBT.Visible = false;
LoginBT.Visible = true;
}
}
protected void LoginBT_Click(object sender, EventArgs e)
{
if (usernameTB.Text != "")
{
if (passwordTB.Text != "")
{
OleDbConnection mdb = new OleDbConnection();
OleDbCommand cmd;
OleDbDataReader rdr;
Connect.DBConnection(mdb);
mdb.Open();
string SQLinfo = "SELECT * FROM Customers WHERE cUserName = '" +
usernameTB.Text.ToUpper() + "'";
string SQLlog = "INSERT INTO Log (lName,lLogIn) " +
"VALUES (@UserName, @Date)";
cmd = new OleDbCommand(SQLinfo, mdb);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
if (passwordTB.Text == (string)rdr["cPassword"])
{
Session["sName"] = rdr["cName"];
Session["sUserName"] = rdr["cUserName"];
Session["sAddress"] = rdr["cCoAddress"];
Session["sCoContact"] = rdr["cCoContact"];
Session["sPIC"] = rdr["cPersonInCharge"];
Session["sPICContact"] = rdr["cPICContact"];
Session["sEmail"] = rdr["cEmail"];
Session["sStatus"] = rdr["cStatus"];
Session["sFlag"] = "T";
rdr.Close();
cmd = new OleDbCommand(SQLlog, mdb);
cmd.Parameters.Add("@UserName", OleDbType.Char).Value = (string)Session["sCoName"];
cmd.Parameters.Add("@Date", OleDbType.Date).Value = DateTime.Now;
cmd.ExecuteNonQuery();
mdb.Close();
LoggedIn();
break;
}
else
{
rdr.Close();
mdb.Close();
usernameTB.Text = "";
passwordTB.Text = "";
Response.Write("<script>alert('Error signing in')</script>");
break;
}
}
mdb.Close();
}
else
{
passwordTB.Focus();
Response.Write("<script>alert('Please enter your password')</script>");
}
}
else
{
usernameTB.Focus();
Response.Write("<script>alert('Please enter your UserID')</script>");
}
}
protected void LogoutBT_Click(object sender, EventArgs e)
{
OleDbConnection mdb = new OleDbConnection();
OleDbCommand cmd;
Connect.DBConnection(mdb);
string SQLlog = "UPDATE Log SET lLogOut = @Date WHERE lCoName = @Name";
cmd = new OleDbCommand(SQLlog, mdb);
cmd.Parameters.Add("@Date", OleDbType.Date).Value = DateTime.Now;
cmd.Parameters.Add("@Name", OleDbType.Char).Value = (string)Session["sUserName"];
mdb.Open();
cmd.ExecuteNonQuery();
mdb.Close();
LoggedOut();
}
protected void LoggedOut()
{
Session["sName"] = null;
Session["sUserName"] = null;
Session["sAddress"] = null;
Session["sCoContact"] = null;
Session["sPIC"] = null;
Session["sPICContact"] = null;
Session["sFlag"] = "F";
passwordTB.Visible = true;
passwordTB.Text = "";
usernameTB.Visible = true;
usernameTB.Text = "";
usernameTB.Text = "UserID:";
LogoutBT.Visible = false;
LoginBT.Visible = true;
Response.Redirect("OnlineRVform.aspx");
}
protected void LoggedIn()
{
passwordTB.Visible = false;
passwordTB.Text = "";
usernameTB.Visible = false;
usernameTB.Text = "";
usernameTB.Text = (string)Session["sPIC"];
LogoutBT.Visible = true;
LoginBT.Visible = false;
}
0
#2 Nov 3rd, 2009
Check that controls were placed inside form tag of your html markup page.
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
![]() |
Similar Threads
- Simple ASP.Net Login Page using C# (C#)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Asp.net Login Page (ASP.NET)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Getting ComboBox Value
- Next Thread: Query MS Access data based on week selection on Calendar control in Visual Studio
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor application asp asp.net bc30451 bottomasp.net box browser button c# checkbox click commonfunctions confirmationcodegeneration css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal forms formview google grid gridview gudi iframe iis javascript list listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent project radio redirect registration relationaldatabases reportemail richtextbox rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers





