Dhimesh Parmar

Dhimesh Parmar

  • 1.8k
  • 108
  • 5k

I want to Pass Session Name In another page?

Mar 6 2018 12:28 AM
When i click on login button then pass username in my another page?
 
My Code Like This:
  1. Login Page:  
  2. protected void Page_Load(object sender, EventArgs e)  
  3.     {  
  4.         {  
  5.             if (Request.QueryString["out"] != null)  
  6.             {  
  7.                 Session.RemoveAll();  
  8.                 Response.Redirect("Login.aspx");  
  9.             }  
  10.         }  
  11.     }  
  12.     protected void btnLogin_Click(object sender, EventArgs e)  
  13.     {  
  14.         DataTable dt = new DataTable();  
  15.         SqlDataAdapter da = new SqlDataAdapter("select Name from userLogin where Name='" + txtUserName.Text + "' AND Password='" + txtUserPassword.Text + "'", @"Data Source =.\SQLExpress;Initial Catalog = TourPortal; Integrated Security = True");  
  16.   
  17.         da.Fill(dt);  
  18.         if (dt.Rows.Count == 0)  
  19.         {  
  20.             msg = "Please Enter Valid Username And Password";  
  21.         }  
  22.         else  
  23.         {  
  24.   
  25.             Session.Add("UserName", dt.Rows[0][0].ToString());  
  26.             Response.Redirect("Dashboard.aspx");  
  27.   
  28.         }  
  1. another Page:  
  2.   
  3. <a href="#" data-toggle="dropdown" aria-expanded="false">  
  4.                                       
  5.                                     <span class="hidden-xs">----------Need Session Name---------------<i class="fa fa-angle-down pull-right"></i></span>  
  6.                                       
  7.                                     <img src="resources/img/icons/icon-user.png" class="user-image" alt="User Image">  
  8.                                 </a>  
  9.                                 <ul class="dropdown-menu user-menu animated flipInY">  
  10.                                       
  11.                                     <li class="divider"></li>  
  12.                                     <li><a href="Default.aspx?out=1" id="logout"><i class="ti-power-off"></i> Log Out</a></li>  
  13.                                 </ul>  
 

Answers (7)