Master Pages in ASP.NET 2.0 ???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Master Pages in ASP.NET 2.0 ???

  1. #1
    Join Date
    Jul 2005
    Posts
    2

    Unhappy Master Pages in ASP.NET 2.0 ???

    Hi all,

    I so far understand how to acces controls on a master page, but the problem I am having is accessing classes and variable that I create in the C# file of my master page. here's a snippett of two classes being declared on my master page


    private User _user;
    private SAI_Login _login;

    I want to declare these variables on my master page so I can have access to their members throughout my application
    ( Is this a good Idea or the right way to do things)

    now on each of my pages I want to be able to access the above classes and their members


    I know This is how it is done for a Control

    Menu myMenu = new Menu();
    myMenu = (Menu)Master.FindControl("Menu2");

    And Msdn says to create a property for the members in the MasterPage but this does not seem to work with Classes

    Any advice/help would be greatly appreciated. If am am going about it all wrong please be blunt, I would rather do it right than half ***


    Here is a good example of what i'm doing

    My classes on the master page, classes within my namespace

    private SAIWEB.User _user;
    private SAIWEB.SAI_Login _login;

    Here are my public properties

    public User My_user
    {
    get{ return _user; }
    //I don't think I need a set
    }

    public SAI_Login My_login
    {
    get{ return _login;}
    }

    Here is the Header from one of my aspx pages inheriting from this master

    <%@ Page Language="C#" MasterPageFile="~/MasterPages/SAI_BasePage.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login1" Title="Untitled Page" %>


    And here is the code that I am using to try and access the property on my aspx page

    //I declare a local instance of the type of variable or class I want
    SAIWEB.User localUser = master.My_user;

    The line above returns this error
    Error 2 'System.Web.UI.MasterPage' does not contain a definition for 'My_user'


    What am I doing Wrong???????????????

    Please Help

  2. #2
    Join Date
    Dec 2008
    Posts
    5
    It seems you may have forgotten to add a MasterType directive on your Content page like so:
    Code:
    <%@ MasterType TypeName="SAIWEB.Master_Page_Class_Name" %>
    But even with this I cannot get this to work as is... But that's just me, I hope...

    What I have to do in the Content page is this:
    Code:
    public partial class _Default : Page
    {
    	private SAIWEB.MasterClass master;
    
    	override protected void OnInit(EventArgs e)
    	{
    		// link back to master page
    		master = (SAIWEB.MasterClass)base.Master;
    	}
    }
    But I don't know why I am supposed to add this code, this is what I am trying to find out here...

    In your case, just add the MasterType directive...

Similar Threads

  1. Actipro Wizard 2.0 Released (Windows Forms Control)
    By Actipro Software Support in forum dotnet.announcements
    Replies: 0
    Last Post: 03-16-2003, 08:40 PM
  2. QuickAdmin v2.0 Develop ASP.NET site back-end admin pages in minutes
    By David Campbell in forum dotnet.announcements
    Replies: 0
    Last Post: 10-02-2002, 08:52 PM
  3. Replies: 0
    Last Post: 07-02-2002, 09:20 AM
  4. Free ASP.NET Web Matrix Design/Editor Tool Released
    By ASPSmith Training in forum dotnet.announcements
    Replies: 0
    Last Post: 06-18-2002, 04:39 AM
  5. VirtualQueryEx
    By MacDeath in forum VB Classic
    Replies: 2
    Last Post: 02-14-2001, 06:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center