Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I've created a master page having two tabs one for home and other on for info(called About). By default Home page is shown. Their is link for login in master page which takes user to login page. Its not generic login control of .Net framework. On master page there are controls like Login label(ref link to login page), Login name(name of who logged in) and log out link.
At first log out and login name is not visible. Once user logs in these 2 controls would be visible and login control hidden. On successful login i am directing to About.aspx page where i've written the code to make these control visible. But when i click on the home link of they become invisible and Login control becomes visible.
So what i need to do is i need to hide login link button on successful login and login name and logout link button to make visible.
But it should be consistent throughout the application. As i've written the code on About.aspx page it is working for that page only why not for other pages? Is it master page n content page life cycle events? Or I need to make that code as function and run it for every other page in the application containing that master page?

Thanks in advance.
Posted
Updated 21-Jan-11 20:12pm
v2
Comments
TweakBird 22-Jan-11 2:13am    
Edited for Capitalization & Spells.

hey,
one way to control this scenario is (if i have understod the question correctly) that make a session variable. when the user logs in successfully pass the ID of the user to the session. and on the Load event of each page set the propoerty of the controls to hidden.

e.g.
if(SuccessfullLogin)
{
Session["LoggedInUserID"]=ID;
}
else
{
Session["LoggedInUserID]="";
}

then on the Load event of each page
if(String.IsNullorEmpty(Session["LoggedInUserID"].ToString()))
{
Label objLabel =(Label)Master.FindControl("LabelLogin");
objLabel.Visible=True;
}
else
{
Label objLabel =(Label)Master.FindControl("LabelLogin");
objLabel.Visible=False;
}


Hope it will give you the idea.
Best of luck
Ahsan Sarfraz
 
Share this answer
 
v2
Comments
alok lingayat 22-Jan-11 3:57am    
hi Ahsan,
i agree with u. wat im doin here is - on clik of login button im chekin the credintials. if successfull im creating a session var of username and redirectin the user to About.aspx page where ive written the code to make logout(linkbutton) and loginname(lable) controls visible. i tried to make them visible on clik of login button but thats not hapening.how can I aproach this prblm(actually its not a prblm i think. i need a more better approach than wa im doin now. u understand that??)
Thnx and ill appreciate some more help...
One way of acheiving this is like this:

Have the property or function defined in master page.In your child page,you write as below

<%@ MasterType VirtualPath="~/Site1.Master" %> 
And to call the property/function of the master page,from child pages do as below

Master.Property or Master.Function()
 
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