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

  • SEARCH
  • Home
  • 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 3759256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:17:18+00:00 2026-05-19T10:17:18+00:00

I have a page – only ONE page for the entire site: using System;

  • 0

I have a page – only ONE page for the entire site:

using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class CMSPageViewer : System.Web.UI.Page
{
    public int myPageID;

    protected void Page_PreInit(object sender, EventArgs e)
    {
         // Get stuff from the database

         myPageID = 1;

         // Set the Page.MasterPageFile
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Fill in the page contents
        // This looks for and fills in asp:ContentPlaceHolder controls based on ID
    }
}

And the master page:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Standard_Page : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int myID = (this.Page as CMSPageViewer).myPageID;
    }
}

How can I access ID from the MasterPage that is used?

Casting the page doesn’t seem to work. I get the following error:

Compiler Error Message: CS0246: The type or namespace name 'CMSPageViewer' could not be found (are you missing a using directive or an assembly reference?)
  • 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-19T10:17:19+00:00Added an answer on May 19, 2026 at 10:17 am

    Define a variable in your master page. Give it proper getter/setters. In each page call the master.setter and “pass the variable into” the master page.

    At the very least you’re going about it wrong, but this is what you have to do.

    Referencing “ASP.NET 3.5 Unleashed” http://www.amazon.com/dp/0672330113 section in Chapter 5 pages 255 – 260 for modifying Master properties based on the Page being interpreted.

    Again, Referencing ASP.NET 3.5 Unleashed Chapter 6 which starts off:

    Themes are different than Master Pages. A Master Page enables you to share content across multiple pages in a website. A Theme, on the other hand, enables you to control the appearance of the content.

    So in other words, you’re not supposed to use a Master Page as a Theme, the two work together.

    Do you want me to keep going? I’ve got a few other books. I’ve done exactly what you’re trying to do (modify the master based on the content) and at the time I knew it was a hack, but I did it because I had to. So what I’m telling you is what I did, which is what works.

    Now please, again, tell me that what I’m suggesting can’t be done. I’ll go find some more references that will explain why you can’t cast to a Page from within the Master.


    For those looking to lay the smack down on my turning to a book for reference, note that that’s how the big boys play, it’s how the people who get the actual contracts play, and it’s how you inform your boss. It’s a book. That’s what they’re for. Additionally, Stephen Walther is not a nobody, he was a Senior Product Manager for the ASP.NET team. So he knows what the hell he’s talking about. I would listen to his advice. Hell, I bought his book didn’t I?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page using <ul> lists for navigation (Javascript changes the styling to
I have Page A which calls Page B using AJAX. Page B will be
I have page titles like this: $pageTitle = <title>site - {$cat} - {$q} -
I'm using asp.net 3.0. I have Page A doing a Server.Transfer to Page B.
I have page that creates a table: http://gupii.co.uk/rap/weekTable.php and I'm using a plugin to
i have page and it has, <meta http-equiv=Content-Type content=text/html; charset=windows-1254> when i try to
i have page and it has, <meta http-equiv=Content-Type content=text/html; charset=windows-1254> when i try to
I have page, that loads in data using AJAX (a form filter) using jQuery.
I have page handler with 95% traffic, it fetches model from DB using its
I have page with form: @using (Html.BeginForm(Create, Theme, FormMethod.Post, new { id = frm_post,

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.