Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to send username to chaild pages by using cookies in master pages my username is in master page and it should be displayed on my master page for every chaild pages...please help me how to solve this

thanks in advance..
Posted

1 solution

Assuming that you have Username value in Master Page.
This is the sample code i give you.
Write this code in the Master Page Load Event. And set the Cookie value.
C#
protected void Page_Load(object sender, EventArgs e)
{
    HttpCookie MyCookie = new HttpCookie("UserName");
    MyCookie.Value = lblUsername.Text; //set the user name value here.
    MyCookie.Expires = DateTime.Now.AddDays(1); //include cookie expiration time
    Response.Cookies.Add(MyCookie);
}


And to retrieve data from cookie in child page
In the Page_Load event write
C#
protected void Page_Load(object sender, EventArgs e)
{
    string userName = Request.Cookies["UserName"].Value;
}
 
Share this answer
 
Comments
teja sai ravi 21-Nov-13 2:10am    
hi friend thanks for ur reply it is not working in chaild page load iam getting cokkie value null i am having a username text box in my master page when i entered with some username and pass word it is displaying first time on my master page but when i go to some other oage it is disappering please help me
Thomas ktg 21-Nov-13 2:16am    
Make sure that the value username stored in the cookie.
teja sai ravi 21-Nov-13 2:33am    
hi friend it is storing but when it came back from chaild page to master page the value becoming null

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