Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My question is regarding a custom control which I created. This custom control derives from a ListProperty control.

public class CustomListProperty: ListProperty

Normally to call ListProperty on the page I use the following code:

<SharePoint:ListProperty Property="LinkTitle" runat="server"/>

But regarding my custom class I have 2 questions:

1) How can I add in my CustomListProperty a new property to the Property property? Because only this properties are available at this moment (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.listproperty.property)

So if I can put my own property I could call the value from property with following code: <SharePoint:ListProperty Property="NewProperty" runat="server"/> : so that my own value is shown (emphasis Property="NewProperty").

This modification I suppose should happen in Page_Load method. I could say:

base.Property = "NewProperty - somevalue"

But this way doesn't work. I tried to figure out how this Property property works .. I know it returns a string but I don't know how to add new properties to that.

2) The other question is: I want to create a new method in this customListProperty class which I would like to call just like property and it would return a string. What I means is:

public string CustomMethod(string sometext)
{
    retrun sometext;
}

In the page I would add this:

<SharePoint:ListProperty CustomMethod="SomeText" runat="server"/>

How can I provide this kind of method to my control and is this possible? If it is possible how can I also call a method without parameter from the page?

<SharePoint:ListProperty CustomMethod="" runat="server"/>
share|improve this question
    
The property if it is readonly you would not be able to set it, I am not able to check the API at the moment. To be able set base properties they must allow setting the value. –  Ismail Durgut PhD Jul 19 '12 at 7:41

3 Answers 3

The property if it is readonly you would not be able to set it, I am not able to check the API at the moment. To be able set base properties they must allow setting the value.

As for the method you are trying to call in the markup, you can have a property and in the setter of the property you can call your method like:

Public string RunMyMethod { set { MyMethod(); } }

Private void MyMethod() { }

This way setting this property will run your method, so if it is possible for you to override the other property you can call this method and call the base functionality in the same setter like:

Public string RunMyMethod { set { MyMethod(); base.Property = value; } }

share|improve this answer
    
Here you are not overriding base property but you are hiding it. New keyword hides it. You can still store and call base.Property in your property if you want, you can write get {return property + base.Property } for example –  Ismail Durgut PhD Jul 19 '12 at 9:05

Here you are not overriding base property but you are hiding it. New keyword hides it. You can still store and call base.Property in your property if you want, you can write get {return property + base.Property } for example

share|improve this answer
up vote 0 down vote accepted

Here is the full solution. Works perfectly! If someone is interested:

    [DefaultProperty("Property")]
    public class CustomImplementation: ListProperty
    {
        private string property;

        [DisplayName("Property")]
        public new string Property
        {
            get { return property;}
            set 
            {
                base.Property=value;
                if (value.Equals("somevalue"))
                {
                    //implementation
                }
                else if (value.Equals("somevalue"))
                {
                    //implementation
                }
            }
    protected override void Render(HtmlTextWriter output)
    {
        if(string.IsNullOrEmpty(Property)
        {base.Render(output);}
        output.Write(Property);
    }
        }
}

It works very wel, now i can say: And I do get my value ... or i can also use the OOTB properties.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.