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 3801432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:02:58+00:00 2026-05-19T14:02:58+00:00

Take the following scenario. I have multiple ASPX pages. Login, Logout, Main, Messages, etc…

  • 0

Take the following scenario. I have multiple ASPX pages. Login, Logout, Main, Messages, etc… They all inherit from System.Web.UI.Page of course. For all the pages, I want to override the Render method from the Page class. I could easily copy and paste the same code into each page like so:

protected override void Render(HtmlTextWriter writer)
{
     //Code Logic Here
}

But if I had many pages, lets say 20, maintaining the code in each page could get very time consuming and error prone.

That made me think a bit and I thought okay lets try this…override the function in each page but call a static function. That way changing the static function would result in a change for every page. Which works fine… But its not really nice and clean, having to override like that on every single page. Anybody have any ideas or thoughts on this one? Perhaps something simple I am overlooking? Thanks

EDIT: Some pages use the System.Web.UI.Page class and some pages inherit from another class called ModifiedPage which inherits and overridies other functions of the System.Web.UI.Page class. So its not as simple as inheriting all the pages from one class.

EDIT2: All pages need this behavior, some already derive from another class, and I am unable to change the implementation or inheritance hierarchy of that other class.

  • 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-19T14:02:58+00:00Added an answer on May 19, 2026 at 2:02 pm

    Instead of inheriting from System.Web.UI.Page, have them all inherit from MyProject.MyBasePage which inherits from Page:

    public abstract class MyBasePage : System.Web.UI.Page
    {
        protected override void Render(HtmlTextWriter writer)
        {
            //Code Logic Here
        }
    }
    

    and…

    public partial class MySpecificPage : MyBasePage
    {
    }
    

    Edit

    Clarification added to the question now points out the real puzzle – the pages which all need this common Render logic have different inheritance paths. That is more tricky in c#, and you won’t be able to avoid at least a little bit of redundant plumbing code. There’s plenty of different ways to handle this – here’s one approach I have taken in the past:

    1) Create an interface for this common functionality. For example, IOverrideRender:

    public interface IOverrideRender
    {
        void Register(OverrideRender render);
    }
    
    public delegate void OverrideRender(HtmlTextWriter writer, Action<HtmlTextWriter> original);
    

    2) Each page which needs this functionality gets the interface and wires it like so:

    public partial class MyPage : Page, IOverrideRender
    {
        void IOverrideRender.Register(OverrideRender render)
        {
            this.overrideRender = render;
        }
    
        private OverrideRender overrideRender;
    
        protected override void Render(HtmlTextWriter writer)
        {
            if(overrideRender != nul)
            {
                overrideRender(writer, base.Render);
            }
            else
            {
                base.Render(writer);
            }
        }
    }
    

    3) In an HttpModule, check to see if the handler is IOverrideRender and if so, pass in your custom render method:

    public class OverrideRenderModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += this.HandlePreRequestExecute;
        }
    
        private void HandlePreRequestExecute(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            IOverrideRender overridable = app.Context.CurrentHandler as IOverrideRender;
            if(overridable != null)
            {
                overridable.Register(
                    (writer, original) => {
                        writer.Write("Hello world"); //custom write
                        original(writer); //calls base.Render
                });
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the scenario where you have the following application: An MVC 4 Web App
I have the following scenario: Program P (can take upto 30 minutes to complete)
I have the following scenario : I’m pushing 100 messages to a queue shared
I have a problem getting the following scenario to work. A student can take
Take the following scenario: Public Class Store Public Overridable Property Areas As List(Of Area)
Take the following example, I have a class public class SomeItem { public string
Take the following : #include <stdio.h> main() { unsigned long long verybig = 285212672;
Let's assume we have the following generic scenario: An RDBMS as a data source,
Is there a naming convention for the following scenario: I have a project which
I was working with spring-ehcache-annotations and came across following scenario: I have a simple

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.