SharePoint 2010 introduced a quantum leap forward with the introduction of Visual Web Parts development integration with Visual Studio 2010. Most developers that have worked with SharePoint for any length of time are familiar with hosting custom ASPX pages inside SharePoint web parts. Doing so allows us to present robust applications and interfaces inside the SharePoint portal and fully utilize all of the robust security features and other goodies that come with SharePoint. The introduction of Visual Web Part development eliminates the need for separate web sites and pages since the custom web part becomes an integrated component of the SharePoint application. All of this comes without having to use STSDEV, VSeWSS, or the like. We can simply build the web part right inside Visual Studio and click Deploy! A really great feature is the ability run & debug right from Visual Studio without any special configuration required. All of this greatly simplifies and expedites the development of custom enhancements to a SharePoint application and is no doubt Microsoft’s response to the fact that the number of SharePoint developers continues to grow, as does the number of SharePoint implementations.


For those who have not yet delved into Visual Web parts, this link will take you to MSDN for a quick jump start:

One of the advantages of using custom web parts and ASPX applications is the ability to integrate data & functionality from outside systems, such as ERP applications, into the SharePoint  environment. Users can view live orders, inventory data, or other mission critical information and even make updates without ever leaving the portal. In order to provide this robust functionality, we often need to use data grids, combo boxes, tree views, etc. to provide a fully functional user experience. All of this is possible (and easy) with the Visual Web Part development environment. One can even utilize 3rd party controls such as Telerik or Infragistsics .NET AJAX controls. Essentially, most anything you can do on a stand alone ASPX.NET page can be done with your web part. There are a few catches, though.

To provide your users with the best experience, you will naturally want to utilize the AJAX functionality that most web controls now provide. Your web part is going to reside on a page that will be served up by the SharePoint server and this host page will contain its own script manager by default. Unfortunately, this script manager cannot “see” the controls on your web part and therefore cannot control AJAX responses for them. You will find that simply including a script manager on your web part like you would do on a stand alone ASPX page will not work either. The two script managers will conflict with each other and the SharePoint master page will prevail. Fortunately, there is a simple solution for this that makes both script managers happy and allows them both to work in harmony.

You will note that when the Visual Web Part project is created that you will get three files, one of which is the code file which contains methods that add controls to the Web Part and generate custom content within the Web Part. The key method in this file is the CreateChildControls() method as shown below.

   1: protected override void CreateChildControls()
   2: {
   3:     Control control = this.Page.LoadControl(_ascxPath);
   4:     Controls.Add(control);
   5:     base.CreateChildControls();
   6: }

The trick is to add your script manager here and configure the affected controls rather than to perform these actions in your ASPX as usual. Below is an example demonstrating how to add a Telerik RadAjaxManager and RadAjaxLoadingPanel to the web part and to configure several controls. This sample uses the Telerik control, but any script manager control can be used. The key point is to add the controls and configure them here. This will provide the full AJAX functionality within your web part while allowing SharePoint to also function normally.

   1: protected override void CreateChildControls1()
   2: {
   3:     Control control = Page.LoadControl(_ascxPath);
   4:     Controls.Add(control);
   5:     // Ajax manager & loading panel
   6:     RadAjaxManager RadAjaxManager1 = new RadAjaxManager();
   7:     RadAjaxLoadingPanel loadingPanel = control.FindControl("RadAjaxLoadingPanel1") as RadAjaxLoadingPanel;
   9:     //Add first control (DataGrid1) and updated controls
  10:     Control ajaxcontrol = control.FindControl("DataGrid1");
  11:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, (RadGrid)control.FindControl("DataGrid2"), loadingPanel);
  12:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, (RadGrid)control.FindControl("DataGrid3"), loadingPanel);
  13:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, (RadToolBar)control.FindControl("RadToolBar1"));
  14:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, control.FindControl("ComboBox1"));
  15:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, control.FindControl("ComboBox2"));
  16:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, control.FindControl("RadPanelBar1"));
  17:     // Add second control (ComboBox1) and updated controls
  18:     ajaxcontrol = control.FindControl("ComboBox1");
  19:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, (RadGrid)control.FindControl("DataGrid1"), loadingPanel);
  20:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, control.FindControl("ComboBox2"), loadingPanel);
  21:     RadAjaxManager1.AjaxSettings.AddAjaxSetting(ajaxcontrol, control.FindControl("RadToolBar1"));
  23:     // continue as needed
  24: } 

In summary, you can create your web part in Visual Studio utilizing whatever controls suit your needs. Once in place, implement your script manager inside CreateChildControls() and configure as needed. Prepare your end users to be dazzled.