Monday, 10 June 2013

Creating The Poperties with in the WebPart

Creating The Poperties with in the WebPart

Open VS2010 --->
    New ---> 
    Project ---> 
    Visual C# --> 
    SharePoint ---> 
    Empty SharePoint Project ---> 
    [WpDemos] ---> OK

    Solution Explorer ---> Right Click ---> Add New Item ---> WebPart ---> Wp1Sample ---> OK

Write the following code 
1. Add New webpart
2. 
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls; 
namespace CustomProperties.CustomPropertiesWP
{
[ToolboxItemAttribute(false)]
public class CustomPropertiesWP :WebPart
{
private string  strValue;
Label lblResult;
Button btnClick;

[System.Web.UI.WebControls.WebParts.WebBrowsable(true),
System.Web.UI.WebControls.WebParts.WebDisplayName("Enter the Value"),
System.Web.UI.WebControls.WebParts.WebDescription("Please Enter the Value"),
System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
System.ComponentModel.Category("Madan Custom Properties"),
System.ComponentModel.DefaultValue("")]

public string  propValue
{
get { return strValue; }
set { strValue =value; }
}
protected override void CreateChildControls()
{
       lblResult = new Label();
       btnClick = new Button();
       btnClick.Text = "Click";
       btnClick.Click += new EventHandler(btnClick_Click);
      this.Controls.Add(lblResult);
      this.Controls.Add(btnClick);
}

protected void btnClick_Click(object sender,EventArgs e)
{
      lblResult.Text = propValue.ToString(); 
}       
    }
}

Build and Deploy

No comments:

Post a Comment