0
檢索。 這裏是我的代碼,請幫我... MasterPage.master.cs會話名稱未在母版頁
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["name"] == null)
{
Panel2.Visible = false;
Panel1.Visible = true;
}
else if (Session["name"] != null)
{
Panel1.Visible = false;
Panel2.Visible = true;
Label2.Text = "WELCOME | Mr." + Session["name"].ToString();
}
}
}
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
}
我homepage.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
string st="select Label4,Label3 FROM Register1_master WHERE Label4='" + TextBox1.Text + "' and Label3='" + TextBox2.Text + "'";
cmd = new SqlCommand(st, sqlcon);
cmd.Connection.Open();
string result= null;
Object value=cmd.ExecuteScalar();
if (value != null)
{
result = value.ToString();
Session["name"] = TextBox1.Text;
Response.Redirect("Main.aspx");
}
else
{
Label3.Text="Invalid username or password";
}
cmd.Connection.Close();
}
從主頁,我會在登錄後請繼續Main.aspx page
my Main.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HyperLink link = (HyperLink)Master.FindControl("HyperLink1");
link.Visible = false;
HyperLink link1 = (HyperLink)Master.FindControl("HyperLink2");
link1.Visible = true;
Label masterlbl = (Label)Master.FindControl("Label2");
string login = Convert.ToString(Session["name"]);
Session["name"] = login;
}
}
F9 - >會話[ 「名稱」] = TextBox1.Text; F9也在 - > Session [「name」] = login; 你確定你打這個聲明?什麼是價值? – InferOn
你確定你的項目中啓用了sessionstate嗎?請參閱:http://msdn.microsoft.com/en-us/library/h6bb9cz9(v=vs.85).aspx – Matthijs
請使用string st =「select * FROM Register1_master WHERE Label4 ='」+ TextBox1.Text +「 '和Label3 ='「+ TextBox2.Text +」'「; –