Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone ...
I have a C# Web Component(Web User Control) that i made it by myself in Visual Studio 2010 .
Now i wanna create some properties for it . I mean some properties like ASP.Net
component's properties. ASP.Net component's properties are categorized and could have nested properties as well as properties that can get and set a list of data . I need a very clear solution for this purpose .
could you please someone help me .


Web User Control : That contains HTML page for design and a code behind page(C#)

<img src="http://imageupload.co.uk/files/rgrbuqi9fp62aifc1cnc_thumb.png" border="0" alt="Image Upload" />





This is an image of a ASP.Net Chart and Chart's properties .

I wanna create a Web User Control that contains some properties for example like ASP.Net Chart's properties

<img src="http://imageupload.co.uk/files/nuces2yemigtptubpzsc_thumb.png" border="0" alt="Image Upload" />
Posted
Updated 30-Sep-13 8:17am
v5
Comments
Azee 29-Sep-13 15:13pm    
You mean a property that you could access from aspx page where you might use the Control?
Mohammad Sadegh Zohari 29-Sep-13 15:30pm    
No.I mean a property that a programmer can use in design time .
Like TextBox's Properties that you can use them . Actually i wanna make an ASP.Net Component (Web User Control) that Web Developers can use it in their own Websites .
Homero Rivera 30-Sep-13 10:54am    
I really think you need to use screenshots or additional examples to make the point of the question. Adjectives such as "Professional", "nice interface" are still too vague. Considering describing what you see on screen and/or adding screenshots. Thank you.
Mohammad Sadegh Zohari 30-Sep-13 14:28pm    
Thank you for your comment . I've just edited my question . I've also inserted 2 image's link . please read the question again .The things that are very important to me are :
1) nested properties
2) properties that can get and set a list of data like Series property in ASP.Net Chart
Homero Rivera 30-Sep-13 15:56pm    
Fheh! I'm afraid I'll have to forfeit, Sadegh, I'm sorry. Good luck.

1 solution

Whether you create a new control from scratch or inherit from another one, you need to add variables that will hold the property value, and properties which will work as methods would.

Let's say your control will have property ControlSize, not determined by a number, but a choice out of 3, example "Small", "Medium", "Big".
You could allow the user to pick from numbers 1, 2, 3 and make it an int property, but let's better use an enumeration (for ellegance).

Add:
C#
enum Sizes {Small, Medium, Big}

And then a variable of this type, but make sure to make it private:
C#
private Sizes controlsize;

Then the property, which is in fact the one the developers will see (therefore, this one goes public):

C#
public Sizes ControlSize
{
    get { return controlsize; }
    set 
    {
        controlsize = value;
        
        if (controlsize = Sizes.Small)
             this.Size = new Size(10, 10); 
        else if (controlsize = Sizes.Medium) 
             this.Size = new Size(20, 20); 
        else if (controlsize = Sizes.Big)
             this.Size = new Size(30, 30);
    }
}

The property will cause both to change the property value as well as the actual size.
Hope this helps!

PS "Size" will only exist from the System.Drawing library, so you'll need
using System.Drawing; in the header.
 
Share this answer
 
v3
Comments
Homero Rivera 29-Sep-13 23:45pm    
I invite anyone who downvotes an answer to provide a reason. Thank you.
Mohammad Sadegh Zohari 30-Sep-13 4:10am    
Well thanks . With this solution we can only create a drop down list property But how about the other features ?Let's look at the ASP.Net Chart's properties.
ASP.Net Chart's properties are categorized and there is some property with the same name in different categories , as well as properties that can accept a list of data , not just only a number or a name . if you take a look at chart's properties you'll see the other kind of properties . For example you can choose color or font through that properties . Thanks for your solution but i need a more complete solution .
Homero Rivera 30-Sep-13 10:17am    
Do you think you can add a screenshot of what you are looking for in the question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900