Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1046573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:10:00+00:00 2026-05-16T16:10:00+00:00

There are different ways to set the title for content pages from Master page

  • 0

There are different ways to set the title for content pages from Master page

  1. by findcontrol
  2. by creating property in master page and setting the value in content page

As both method requires an object creation of master page which will be little heavy
myMasterPage myMaster = (myMasterPage)this.Master;

so I have tried it by creating a class and it worked –

public class clsmaster
{
    public static clsmaster objmaster = new clsmaster();
    public strtitle {get;set;}
}

Now I just need to access this static object and set the property in the content page and in the master page I just need the controls to take the value from this class (clsmaster).

I would like to know which one is the better approach and why with description please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:10:01+00:00Added an answer on May 16, 2026 at 4:10 pm

    I generally advise creating a BasePage class of some sort that encapsulates the behavior you want through all of your pages, these objects are assumed to always have the same master page, if you need other setups then you can create other objects as necessary.

    From there you can create some properties or methods to allow the BasePage objects to access the master page or its associated properties in a very easy to code way such as this.Title = “MyTitle”

    You can get fancier and create some virtual methods on your BasePage class that you can then override on the physical pages as necessary, to set titles, etc, as needed, without ever grabbing the Master page object directly (which yes, is annoying and ugly). This might look something like this.Title = GetTitle(); (GetTitle is a virtual method on the BasePage that is overridden in the child pages as needed for those pages you want to set a title for).

    This makes strong use of inheritance and lets you add functionality to all of your pages very easily, it may be overkill for what your doing but I’ve never found a situation that was too simplistic for this architecture, it just works really well. I personally find this design far better than constantly using FindControl(), which tends to be error-prone when control ID’s change, etc.

    1. FindControl() is bad because if the control ID’s change, then you might forget to update them in the FindControl reference, and now it’ll break the next time its executed, I stay well away from static stuff like this if at all possible for this very reason, it’s a cheap, quick but error-prone solution.

    2. Accessing the Master page directly isn’t inherently bad, I just can’t stand stuff like:

      myMasterPage myMaster = (myMasterPage)this.Master

    Gets old, is uglier than it needs to be, wrap it in an accessor property at the very least 😉

    I like the following better:

    Title = "My Title"; // Property
    

    or

    Title = GetTitle(); // Virtual method
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are different ways to set a member variable from the constructor. I am
In Yii there are many different ways to get CSS into your pages. The
in javascript there are so many different ways to set up a method for
I am processing strings with a date somewhere in it. There are different ways
There are several different ways I can initialize complex objects (with injected dependencies and
In struts I notice there are two different ways to access variables. I am
There seem to be a number of different ways in which one can create
First off, I know there are many different easier/reliable ways to perform what I
Is there any difference between following two ways of creating an object. Student s1
It occurs to me that there are number of different ways to structure conditional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.