
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.33 KB | hits: 14 | expires: Never
Hiding login panel in master page when users logged in. (ASP.net)
protected void Button1_Click(object sender, EventArgs e)
{
//hide panel doesn't work
Panel1.Visible = false;
//
SqlCommand cmd = new SqlCommand();
string str = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\ava\Desktop\WebSite3\App_Data\news.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(str);
conn.Open();
cmd.CommandText = "select * from users where username=@name and pass=@pass";
cmd.Connection = conn;
cmd.Parameters.AddWithValue("name", user.Text);
cmd.Parameters.AddWithValue("pass", pass.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Panel1.Visible = false;
Panel2.Visible = true;
FormsAuthentication.SetAuthCookie(user.Text, true);
FormsAuthentication.RedirectFromLoginPage(user.Text, true);
Response.Redirect("/website3/karbar/karbar.aspx");
}
else user.Text = "Incorrect name or pass";
}
if(Request.IsAuthenticated)
{
Panel1.Visible = false;
Panel2.Visible = true;
}
Panel1.Dispose();
Panel1.Style.Add(HtmlTextWriterStyle.Display, "none");
protected void Button1_Click(object sender, EventArgs e)
{
((Panel)YourMasterPageID.FindControl("YourPanelID")).Visible = false;
}