Click here to Skip to main content
15,924,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have begun developing WebParts,
My first webpart has this code:

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls.WebParts;

namespace Sample.DisplayMessage
{
    [
     WebBrowsable(true),
     WebDescription("Displays a custom message"),
     WebDisplayName("Display Message"),
     Personalizable(PersonalizationScope.User)
    ]
    public class DisplayMessageWebPart : WebPart
    {
        private string customMessage = "Hello, world!";

        public string DisplayMessage
        {
            get { return customMessage; }
            set { customMessage = value; }
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            writer.Write(DisplayMessage);
        }
    }

}


Some errors appear and I don't understand how to rectify them.

Can you tell me what is wrong with this code and how to get the right version of the code?

Thank you.

UPDATE from OP:
For example the attribute WebBrowsable is not valid in this kind of declaration it tells me that it is valid in the declaration of indexer or property.
Posted
Updated 9-Feb-11 6:10am
v4
Comments
Prerak Patel 9-Feb-11 5:26am    
What errors you get?!
Nithin Sundar 9-Feb-11 5:37am    
Unless you post the errors it will be difficult to judge as to what is going wrong.

1 solution

Look at the simple example on this page; http://www.developer.com/net/asp/article.php/3627871/Writing-Custom-Editors-for-WebParts.htm[^]

The WebBrowsable attribute is contained withing the class declaration, in the code you have above, it is between the Namespace and Class declaraions.

Do you need to move it within the class at the relevant point?
 
Share this answer
 

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