Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
HTML
<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
C#
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

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.
 
Share this answer
 
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.

C#
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900