Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / March 2006

Tip: Looking for answers? Try searching our database.

Reference Controls in MasterPage?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
clintonG - 19 Mar 2006 22:57 GMT
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
CaffieneRush@gmail.com - 20 Mar 2006 01:41 GMT
Just a guess. You're trying to access a non static member from a static
method.
clintonG - 20 Mar 2006 03:16 GMT
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

> Just a guess. You're trying to access a non static member from a static
> method.
CaffieneRush@gmail.com - 20 Mar 2006 17:52 GMT
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
clintonG - 20 Mar 2006 23:39 GMT
Yes, I've done both already used elsewhere in the application. Intellisense
will not "see" the FindControl method in the class.

<%= Clinton Gallagher

> Have you tried to use FindControl to get a reference to
> MemberLoginStatus within the Master Page.
[quoted text clipped - 14 lines]
> 'Within the content page.
> Ctype(Me.Master, CorporateMaster).MemberLoginStatus.Enabled = True
CaffieneRush@gmail.com - 21 Mar 2006 00:25 GMT
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.
clintonG - 22 Mar 2006 17:56 GMT
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

> That's odd.
> I tested both techniques and verified that they both work before
[quoted text clipped - 9 lines]
>
> Finally, check if you've referenced your master page properly.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.