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;

    }

Edited by Reverend Jim: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by mailme.vibin
0

if u r using a content place holder...in 2008 .net u need to refer that first then the button..may be this wil help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.