Shyju
Shyju

Reputation: 218962

How to add custom property to asp.net custom server control?

I have created an asp.net custom control and now want to pass some values to it from the page which will use the control.Is there any way i can add my own property to the control (like Text property is present for a Label control) ?

Upvotes: 0

Views: 4914

Answers (4)

karlis
karlis

Reputation: 920

just add it as public property, then it should be useable for your needs.

Upvotes: 1

dparker
dparker

Reputation: 1082

Adding a property to a custom control in asp.net is no different than adding a property on any class in C# (for instance).

public class Custom : Control
{
    public string Text { get; set; }
}

Upvotes: 1

mpaton
mpaton

Reputation: 789

Assuming ASP.NET 3.5+ just create properties

public string YourProperty {get; set;}

Would be declarative on the control

Upvotes: 4

John Saunders
John Saunders

Reputation: 161831

It's a class. Add a public property to it.

Upvotes: 5

Related Questions