Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
i am making a website in that i want to change the login label of the master page to the username who has logged in and the register link should change to logout and when i click on logout link it should end the session and change the links to default login and register again....
Master page in which i want to change the links
Master.master
<table class="auto-style1">
            <tr>
               
                <td class="auto-style2"><a href="Signin.aspx" class="auto-style9" ><span class="auto-style5" id="signup2">Sign Up</span></a></td>
                <td><a href="Register.aspx" class="auto-style9"><span class="auto-style5">Register</span></a></td>
          </tr>
        </table
Signin page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
 

 
public partial   class Signup : System.Web.UI.Page
{
    bool flag = false;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    public void Signin()
    {
        string login = txtlogin.Text;
        SqlCommand com;
        SqlDataReader dr;
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["Carzz"].ToString();
        con.Open();
        com = new SqlCommand("select RPassword from Registeration where REmail_id='" + login + "'", con);
        dr = com.ExecuteReader();
        if (!dr.Read())
        {
            Response.Write("<script>alert('Invalid User')</script>");
        }
        else
        {
            if (dr[0].ToString() == txtpass.Text)
            {
                Session["Username"] = login;
                flag = true;
                Response.Redirect("~/Home.aspx");
                
                
            }
            else
            {
                Response.Write("<script>alert('Invalid Username or Password')</script>");
                txtpass.Focus();
    }
        }
    }
        
    protected void btnsignin_Click(object sender, EventArgs e)
    {
        Signin();
        
 
            }
 
        }
 
    
Posted 4-May-14 4:33am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

create 4 links login, logout, register and username. Once you have logged in user i.e session is active hide the two links login and register and show other two.
If you find session inactive. hide these two and show other.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi,
i guess you redirect to the Home.aspx if the login details matches. so my suggestion is to do changes from page load on home.apsx.put following code.
 
 protected void Page_Load(object sender, EventArgs e)
        {
 
         // this will set the username to login 
         ((Label)Master.FindControl("signup2")).Text = Session["Username"].ToString();
 
        }

using that code you can access master pages's controls. But my suggestion is to have separate links to Login Log out and register. you can show or hide them as it needed.
 
thanks. hope this helps.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 285
2 Shweta N Mishra 244
3 Mathew Soji 225
4 BillWoodruff 200
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 4 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100