How to create abstract user control with abstract UI elements

Hello,

I am trying to create an abstract class that will enforce the user to include certain UI elements on the page. I am fairly sure this is NOT possible, but I wanted to ask anyway.  
public abstract class ListingControl : System.Web.UI.UserControl
{
  System.Web.UI.WebControls.TextBox MyTextBox { get; set; }
}

Open in new window

public partial class InheritAbstract : ListingControl
{
}

Open in new window

digitalpacmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

saraganiCommented:
What's your purpose?

Ok, you have created an abstract class that contains a property of a TextBox, what do you do with it?
(Do you want to show the TextBox in a specific location?, or that it will fill the whole ListingControl  area?)
0
digitalpacmanAuthor Commented:
I want to enforce the UI elements available on a page.
So when someone implements a class, interface, whatever it is... that they are FORCED to include certain elements on the page.

And I want this shared class to be able to handle the processing for all events and post backs on the page. So all the logic is shared. The position of the UI elements can be changed.

Also each page may have unique changes in functionality which I would handle by running the functionality then calling the base.
0
digitalpacmanAuthor Commented:
What I don't want to do:

Make a concrete class that I inherit with all the UI members, and on preinit check for NULL in all the UI properties and throw an error if one is null.
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Todd GerbertIT ConsultantCommented:
I'm inclined to agree with you in that it's likely not possible - I can't be absolutely certain, but I can't see anyway to make such a thing work.  It seems the best you can do is force the existance of a TextBox property, but then there's no guarantee that property's implementation corresponds to an item in your page's markup.

A MasterPage is the first thing that occurs to me thinking of things to force UI elements, but I don't think that's quite what you're looking for...?

A little more information on your desired end-result would be useful I think...
0
digitalpacmanAuthor Commented:

I want to make a class that represents a page (cs only).
It has everything on it. The events, properties, methods, everything.
I want to then be able to hook it up to any UI that implements the correct UI elements.

Since the page will likely error if certain UI elements are missing, I wanted them to forcefully be implemented in the ASPX page. If you have an element with an ID, and the class definition contains a field with the same name as the ID and type, then it will link them together. If you do not do this, the field becomes null. This linking does not happen when you have a property, it must be a field.

Interfaces are only supported for implementation of properties, of course.

I am working on a project where you build a website (a project) and implement everything in it in multiple websites. The goal is to create controls/pages that will be shared across multiple websites and have to write as little code as possible when carrying over to other sites.

To accomplish this I wanted to create a base class per page, and inherit the base class in the website. Then define the ASPX in the website and make any slight modifications to processing if necessary through overrides.
0
digitalpacmanAuthor Commented:
I should add the goal is to force the error at build time, not run time. Run time errors could easily leak through and go to production if testing is not good enough.
0
Todd GerbertIT ConsultantCommented:
That was a good explanation, thanks...I'm think I'm catching up to you now. ;)

So we want to create a base class with all the functionality already implemented, but in order for the code in the base class to work certain elements must exist on the more-derived Page, and want to create a compile-time error?

Hmm, lemme think about that a minute...
0
digitalpacmanAuthor Commented:
This is what I currently have:
public class EditAddress : XXX.Web.UX.Page
	{
		#region Events
		protected override void OnInit(EventArgs e)
		{
			uxCompleteButton.Click += new EventHandler(uxCompleteButton_Click);

			uxPickupAddress.AddressID = 5;
			uxDeliveryAddress.AddressID = 5;

			base.OnInit(e);
		}

		protected void uxCompleteButton_Click(object sender, EventArgs e)
		{
			uxPickupAddress.SaveAddress();
			uxDeliveryAddress.SaveAddress();

			string redirectionUrl = "/default.aspx?message=" + string.Format(Lang.AddressCompletionMessage, uxPickupAddress.AddressID);
			Response.Redirect(redirectionUrl);
		}
		#endregion

		#region WebControls
		public XXX.Web.UX.UserControls.Address uxPickupAddress;
		public XXX.Web.UX.UserControls.Address uxDeliveryAddress;
		public System.Web.UI.WebControls.Button uxCompleteButton;
		#endregion

Open in new window

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditAddress.aspx.cs" Inherits="XXX.Web.UI.EditAddress" %>

    <XXX:Address runat="server" ID="uxPickupAddress" />
    <XXX:Address runat="server" ID="uxDeliveryAddress" />

Open in new window

public partial class EditAddress : XXX.Web.UX.Pages.EditAddress
	{

	}

Open in new window

0
digitalpacmanAuthor Commented:
I got it working. You have to right click the ASP.Net Web Application and say convert to "Convert to web Application" <-- very funny stuff.

After that everything works.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
digitalpacmanAuthor Commented:
I solved the problem myself.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.