Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.33 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Hiding login panel in master page when users logged in. (ASP.net)
  2. protected void Button1_Click(object sender, EventArgs e)
  3. {
  4.     //hide panel doesn't work
  5.     Panel1.Visible = false;
  6.     //
  7.     SqlCommand cmd = new SqlCommand();
  8.     string str = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\ava\Desktop\WebSite3\App_Data\news.mdf;Integrated Security=True;User Instance=True";
  9.     SqlConnection conn = new SqlConnection(str);
  10.     conn.Open();
  11.     cmd.CommandText = "select * from users where username=@name and pass=@pass";
  12.     cmd.Connection = conn;
  13.     cmd.Parameters.AddWithValue("name", user.Text);
  14.     cmd.Parameters.AddWithValue("pass", pass.Text);
  15.  
  16.     SqlDataReader dr = cmd.ExecuteReader();
  17.  
  18.     if (dr.HasRows)
  19.     {
  20.         Panel1.Visible = false;
  21.         Panel2.Visible = true;
  22.  
  23.         FormsAuthentication.SetAuthCookie(user.Text, true);
  24.         FormsAuthentication.RedirectFromLoginPage(user.Text, true);
  25.         Response.Redirect("/website3/karbar/karbar.aspx");
  26.  
  27.  
  28.     }
  29.     else user.Text = "Incorrect name or pass";
  30. }
  31.        
  32. if(Request.IsAuthenticated)
  33. {
  34.         Panel1.Visible = false;
  35.         Panel2.Visible = true;
  36. }
  37.        
  38. Panel1.Dispose();
  39.        
  40. Panel1.Style.Add(HtmlTextWriterStyle.Display, "none");
  41.        
  42. protected void Button1_Click(object sender, EventArgs e)
  43. {
  44.    ((Panel)YourMasterPageID.FindControl("YourPanelID")).Visible = false;
  45. }