How to disable Master Page controls on Login Page?

L

luqman

I have created a Login Page with Master.Master Page. The master page
contains Menus, and I want to disable those menus on Login Page, how can I
?

Best Regards,

Luqman
 
M

Mark Rae [MVP]

I have created a Login Page with Master.Master Page. The master page
contains Menus, and I want to disable those menus on Login Page, how can I

In the Page_Load of your Login page you can refer to the controls on its
MasterPage as follows:

Menu MyMasterMenu = (Menu)Master.FindControls("MyMenu");

Then you can do anything you like with it...
 
G

Guest

Expose a property from the master page i.e.

public bool ShowMenu
{
get
{
return myMenu.Visible;
}
set
{
myMenu.Visible = value;
}
}

On the page you utilize your master, use <@ MasterType > directive to
specify the type your master is:

<@ MasterType Type="myMasterPageType" >

and then, in the page code you can use your property:

this.Master.ShowMenu = true;

Mark's approach is relatively simpler, but it won't work if the menu is
nested in a container, it's not supported by the intellisense and compiler,
and you need to know the control structure of the master page (including IDs).

hope this helps
 
M

Mark Rae [MVP]

Mark's approach is relatively simpler, but it won't work if the menu is
nested in a container,

Surely the programmer would know how to find controls on a page no matter
how deeply they were nested in other containers... :)

Also, the OP was asking how to disable the Menu, not make it visible or
invisible...
 
G

Guest

Hi there,

I agree Mark, but i've seen this apporach causing problems when other
developers changed the master. From my point of view, using property it's
much more reliable because property is transparent for the caller, and any
bugs will be intercepted by the compiler. In addition, if the menu is put
inside a container, you would have to use $ separator to find the control
which is another source of bugs if control tree on master changes. Anyway,
both solutions are valid.

Best regards
 
M

Mark Rae [MVP]

From my point of view, using property it's much more reliable because
property is transparent for the caller, and any bugs will be intercepted
by the compiler.

Fair enough.
In addition, if the menu is put inside a container, you would have to use
$ separator to find the control

Not so...

Menu MyMasterMenu =
(Menu)Master.FindControl("MyContainer").FindControl("MyMenu);

However, I agree that that is pretty dreadful... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top