1/12/2012

How To Add Custom Web Part Properties To Visual Web Part In SharePoint 2010

How To Add Custom Web Part Properties To Visual Web Part In SharePoint
2010
Hey Folks,

Let's see how we can add custom web part properties to a visual web part in SharePoint 2010.

Open Visual Studio 2010 -> File -> New -> Project -> Visual C# -> SharePoint -> 2010 and select Visual Web Part project template as below:



In SharePoint Customization Wizard, validate the SharePoint 2010 site URL as below:



Once Visual Studio 2010 open ups, it will look like below:



Open VisualWebPart1.cs file and add below code:

 

namespace AddCustomProperty.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public class VisualWebPart1 : WebPart
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/AddCustomProperty/VisualWebPart1/VisualWebPart1UserControl.ascx";

private string _Name;
[WebBrowsable(true), WebDisplayName("Name"), WebDescription("My Name"),
Personalizable(PersonalizationScope.Shared), Category("Custom Property"),
System.ComponentModel.DefaultValue("")]

public string Name
{
get { return _Name; }
set { _Name = value; }
}

protected override void CreateChildControls()
{
VisualWebPart1UserControl control = (VisualWebPart1UserControl)Page.LoadControl(_ascxPath);
control.Name = Name;
Controls.Add(control);
}
}
}

 

It should look like below:



Open VisualWebPart1UserControl.ascx file and add below code:







It should look like below:



Open VisualWebPart1UserControl.ascx.cs file and add below code:



namespace AddCustomProperty.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
public string Name { get; set; }

protected void Page_Load(object sender, EventArgs e)
{
NameLiteral.Text = "Your Name is : " + this.Name;
}
}
}



It should look like below:



Deploy The Project:



Final Look:



Thanks & Have Fun!! :)

1/02/2012

Limitation of SharePoint 2010

Limitation of SharePoint 2010
I've found mainly three major limitation of SharePoint 2010.

 

I will arrange them in three manor:

 

1. Simple :

SharePoint 2010 does not support .NET Framework 4.0

 

2. Average :

SharePoint Designer 2010 does not support looping.

 

3. Complex :

Excel services can not connect to SharePoint Data.

 

Thanks & Have Fun!!

1/01/2012

Naimish Pandya [MCTS, MCPD, MVP] - Blog Summary 2011

Naimish Pandya [MCTS, MCPD, MVP] - Blog Summary 2011
Wish You A Very Happy New Year 2012!!

The WordPress.com stats helper monkeys prepared a 2011 annual report for my blog.

Here's an excerpt:
A New York City subway train holds 1,200 people. This blog was viewed about 4,300 times in 2011. If it were a NYC subway train, it would take about 4 trips to carry that many people.

Click here to see the complete report.