• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1134
  • Last Modified:

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

0
digitalpacman
Asked:
digitalpacman
  • 7
  • 2
1 Solution
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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
 
digitalpacmanAuthor Commented:
I solved the problem myself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now