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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:56:07+00:00 2026-05-18T23:56:07+00:00

First, some basic details: I’m using Visual Studio 2008 Team Edition I’m using C#

  • 0

First, some basic details:

  • I’m using Visual Studio 2008 Team Edition
  • I’m using C# ASP .NET 2.0 for a Web Project (not MVC).

The problem

I have a user creation form, I however also need a form to edit user details, which will be identical in terms of the design, apart from the fact that it will pre-load values and use alternate logic in the click event of the form’s button.

I don’t want simply create a copy of this page, as there would be a lot of duplicate code in both the .aspx and aspx.cs files (and I need to do the same for several other forms).

I been using C# .NET WinForms for some time, but this is my first real project using ASP .NET, so I haven’t decided on my favourite approach for this particular problem yet.

I’m looking for, what is considered to be, the best approach to inherit forms in this situation.

Some details on the base form

It currently inherits a master page which contains layout used throughout the website.

It has all the required inputs, each with validation controls, as well as an AJAX update panel to check for username availability. I am of course using the code-behind file for the AJAX post-back, as well as server-side validation (in case client does not have java script enabled).

And of course, the button click event contains all the logic once the inputs have been validated.

My thoughts

I have seen a few different solutions on the net, and based on that I’ve come up with a rough idea of what I think might work out well.

  • Use a nested master page so as to inherit the global layout of the site, as well as contain the base form.

  • Set the controls on the nested master page to be protected, instead of private.

  • Create both the add and edit user pages, inheriting the nested master page, also inheriting the class of the nested master page so as to gain access to all of its controls (I read somewhere that you can’t inherit other pages… not sure yet if the same is true for master pages?)

  • I would then need to override the DoUserSubmit_Click (my form’s button) event to use either creation or editing logic on each page.

  • Would also need to use the Page_Load event on the edit page to populate the values of all of the nested master page’s inputs.

I’ve started an attempt at a nested master page, however, since this inherits the MasterPage class, and not the Page class, the IsValid property isn’t available to me. I’m wondering if I inherit the nested master page into an actual Page with the validation controls exposed, would IsValid work properly from each page?

I’m also not too sure about exposing each of the controls, generally I would keep everything private and setup accessors, however given the number of controls on this form (and the others I want to use this pattern for) it seems like things would be messy that way.

EDIT: I went ahead a bit further with the nested master page, and found that all of its controls are already set to protected, so by inheriting it instead of System.Web.UI.Page, I can access all of the controls.

I wasn’t able to override the click event, but I did use an alternate solution which allows me to enforce some sanity checking, so it works well.

Unfortunately, since the page now inherits my nested master page’s class, and not the Page class, I don’t have access to Page.IsValid, which is pretty important in case client-side validation doesn’t work, or is disabled.

Here’s the solution so far:

In the nested master page:

    /// <summary>
    /// This method is what contains the logic to perform once the form has been submitted.
    /// </summary>
    protected abstract void DoPostBack();

    protected void DoRegister_Click(object sender, EventArgs e)
    {
        if (IsPostBack) //Would prefer to do IsValid check here.
        {
            DoPostBack();
        }
    }

In the add/edit pages:

    protected override void DoPostBack()
    {
        if (IsValid) //IsValid doesn't exist in this context.
        {
            //My logic here...
        }
    }

END EDIT

I’ve also considered creating user-defined controls for each form and just using that on each page, exposing events as necessary. However, from what I’ve read, this doesn’t allow for the proper separation of design from logic, as with code-behind. Though I will admit, I haven’t tried it myself yet.

I didn’t want to delve to deep into my current design choice as there’s probably a much better solution I haven’t thought of yet.

Any suggestions much appreciated. Thanks!

  • 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-18T23:56:08+00:00Added an answer on May 18, 2026 at 11:56 pm

    I think the simplest solution would be to create a user control (.ascx file) to encapsulate the logic. The control can expose some events (for example, Submit) that you can subscribe to in order to perform your custom logic.

    You will probably still have two different pages but in the above case you don’t need to copy-paste almost the same code.

    Read more on user controls in ASP.NET

    — Pavel

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

Sidebar

Related Questions

First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web
I'm building my first ASP.NET MVC application and I am having some troubles with
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
I always coded console applications and learned some basic UML/patterns skills, using C++. Now
This is my first post. I'm trying to do some basic meta-programming with javascript,
Wanting to implement authentication by client certificates I am experiencing some issues. First some
I'm reading input in a C++ program. First some integers, then a string. When
When I need some complex algorithm I first check if there's anything relevant already
Hopefully some Custom Control Designers/Builders can help I'm attempting to build my first custom
I remember first learning about vectors in the STL and after some time, I

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.