all groups > asp.net building controls > march 2006 >
You're in the

asp.net building controls

group:

Reference Controls in MasterPage?


Reference Controls in MasterPage? clintonG
3/19/2006 3:57:57 PM
asp.net building controls: I'm trying to build a class file in App_Code to reference LinkButton
controls located in a MasterPage.
I know how to reference the controls in the MasterPage from Content pages
but I'm having a problem when moving all the code from the various Content
pages into a class. The erroer

// basic use case (base class inherits System.Web.UI.Page)
public class HeaderTabbedNavigation : GlobalBaseClass
{
static void IsEnabled(bool enabled)
{
if(enabled == true)
MemberLoginStatus.Enabled = true;
return;
}
}

// direct access (fails)
HeaderTabbedNavigation.IsEnabled(true);

// error
'MemberLoginStatus' does not exist in the current context

Is this enough information for somebody to tell me what am I doing wrong and
how should I start thinking when creating classes in this context?

<%= Clinton Gallagher

Re: Reference Controls in MasterPage? CaffieneRush NO[at]SPAM gmail.com
3/19/2006 4:41:13 PM
Just a guess. You're trying to access a non static member from a static
method.
Re: Reference Controls in MasterPage? clintonG
3/19/2006 8:16:04 PM
I understand what you mean. As it turns out, it seems a class may have but
one static constructor which takes no parameters but I still get the same
error when not using the static keyword and I have to learn how to access
controls in the MasterPage this way or I'll never master class design.


<%= Clinton Gallagher


[quoted text, click to view]

Re: Reference Controls in MasterPage? CaffieneRush NO[at]SPAM gmail.com
3/20/2006 8:52:08 AM
Have you tried to use FindControl to get a reference to
MemberLoginStatus within the Master Page.

Eg. within the content page.
Dim MemberLoginStatus As LinkButton =
Me.Master.FindControl("MemberLoginStatus")
MemberLoginStatus.Enabled = True

Or you can expose MemberLoginStatus within the master as a property.
Eg. within the master page with a classname of CorporateMaster.
Public ReadOnly Property MemberLoginStatus As LinkButton
Get
Return MasterMemberLoginStatus
End Get
End Property

'Within the content page.
Ctype(Me.Master, CorporateMaster).MemberLoginStatus.Enabled = True
Re: Reference Controls in MasterPage? CaffieneRush NO[at]SPAM gmail.com
3/20/2006 3:25:21 PM
That's odd.
I tested both techniques and verified that they both work before
posting my suggestion.
And there was intellisence support for FindControl() as well. Of
course, the page was not inheriting from a base class page.

Just to be sure, if your master page was set in the base class but not
the sub class then I would do something like the following:
'vb.net code
Dim MyLinkB As LinkButton =
Me.MyBase.Master.FindControl("MyLinkButton")

Finally, check if you've referenced your master page properly.
Re: Reference Controls in MasterPage? clintonG
3/20/2006 4:39:03 PM
Yes, I've done both already used elsewhere in the application. Intellisense
will not "see" the FindControl method in the class.

<%= Clinton Gallagher


[quoted text, click to view]

Re: Reference Controls in MasterPage? clintonG
3/22/2006 10:56:47 AM
I sure appreciate your insights but note I've used properties (early bound)
and the FindControl method (late bound) myself but I'm not trying to inherit
from the Master from a content page. I've been having this conversation in
the Forums [1] and I'm going to try the suggestion to modify the Master to
inherit from a base class itself and then implement properties on the
controls I need to access.

<%= Clinton Gallagher

[1] http://forums.asp.net/1233555/ShowPost.aspx



[quoted text, click to view]

AddThis Social Bookmark Button