Reputation: 115
By reading title of question you would get the idea about my question.
Suppose I'd a button or in master page, which says log in and when user logged in successfully then it'd to change into log out button.
Is it possible ? to change master page control from other pages? and is it possible to change events of master pages (as well as other pages) pragmatically from other pages ?
If yes, then please help me out!
Thanks in advance.
P.S: if you don't understand my question then please ask me, don't report it please!
Upvotes: 1
Views: 558
Reputation: 4903
You can access MasterPage's controls from ContentPage and i can provide you the details, but i think in your case you don't need this and you are in wrong way. You have many other options like putting two login and logout buttons in master page and show or hide them depend on user authentication status.
then after login in content page, do a refresh, so the master page show the correct button. Or as a second solution put login and logout button in a updatepanel, so you don't need even refresh.
I think change events of master pages pragmatically from other pages isn't a good way at all. You just need to create both login and logout buttons and related events and show/hide them depend on authentication status.
Update:
Create login and logout buttons in master page and config related events, then in codebehind in your masterpage in Page_Load
try this:
if (System.Web.HttpContext.Current.Request.IsAuthenticated == true) {
//User is logged in
btnLogin.Visible = false;
btnLogout.Visible = true;
} else {
//User is logged Out
btnLogin.Visible = true;
btnLogout.Visible = false;
}
So every time that masterpage load, depending on authentication's status of user, show the correct buttons.
Upvotes: 1