• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

ASP.NET FindControl on MasterPage

Hello All,

So I'm building a web page in ASP.NET/C# and have created a baseClass which implements login validation.  When my web page code behind is run its class inherits as follows:

public partial class ArchiveDash : LoginBaseClass
{

ArchiveDash is using a single master page with a control on it.  How do I access my master page control from my "LoginBaseClass"?  I tried to reach my controls like this but only received nulls:  (attached below)


//Intercept master page controls
        System.Web.UI.WebControls.HyperLink linkLocalLogIn = (System.Web.UI.WebControls.HyperLink)this.Page.FindControl("linkLogIn");
        System.Web.UI.WebControls.HyperLink linkLocalLogOut = (System.Web.UI.WebControls.HyperLink)this.Page.FindControl("linkLogOut");
        System.Web.UI.WebControls.Label lblLocalWelcomeUser = (System.Web.UI.WebControls.Label)this.Page.FindControl("lblWelcomeBackUser");

        
        //Toggle welcome banner
        if ((linkLocalLogIn != null) && (linkLocalLogOut != null))
        {

Open in new window

0
Phil5780
Asked:
Phil5780
1 Solution
 
kaylanreilorCommented:
If your base class inherits from the master page I think that you should use the Master property instead of Page.
0
 
kaylanreilorCommented:
So, as I said, you have an example here : http://www.west-wind.com/Weblog/posts/5127.aspx.
0
 
masterpassCommented:
This article is one of the most comprehensive and well written about Master page tips and tricks. I hope you will find this extremely useful

http://odetocode.com/Articles/450.aspx
0
 
DreamsTechCommented:
Looks like u r trying to achieve similar to the scenario discussed here:
http://stackoverflow.com/questions/903891/accessing-a-master-page-control-from-a-separate-class
0
 
Phil5780Author Commented:
Thanks allot, I found the same thing:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now