.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Adding webpart programmatically

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :C#


i am adding an webpart programmatically on an button click event but it is not visible in the webpart zone on first click , if i click the button again it will become visible. and page is in edit mode when i am clicking the button.

Any body help out in this issue.




View Complete Post

More Related Resource Links

Creating an Excel Spreadsheet and Adding Data to It Programmatically

The Interoperability services make it veryeasy to work with COM Capable Applications such as Word and Excel. Thisarticle reveals using Excel from a managed application. Excel is thespreadsheet component of Microsoft Office 2000. The majority of Excelprogrammatic functionality is exposed through Automation via the typelibrary Excel9.olb. The intention of this article is to express that amanaged application can interrelate with Excel as a COM server.

Error in / Application after adding employee search in webpart


Hello everyone,

I am working on sharepoint 2007 and I was editing the webpart of the software and after adding the predefined employee search table, the server has crashed while trying to access the server remotely with the following error message:

Error in / Application

However, while trying to login locally I have no problem and can easily login.

What will be the course of action in fixing this error.

Also the site is complaining of an invalid certificate even after adding an exception.

Any help would be greatly appreciated.

Thank You,

Chris Stanko

Adding client event handlers to an ASP.NET controls programmatically



I want to add client event handlers to ASP.NET controls (For example: GridView/Button ) programmatically to ASP.NET.

I am aware of "onclick" event handler, so my code would be

GridView1.Attributes.Add("onclick", "JSGridViewFunction()");

Button1.Attributes.Add("onclick", "JSButtonFunction()");

I want to know what are all the event handlers that are available for (or that can be added to)  ASP.NET controls.

For example, I want to add "onsort" event handler to ASP.NET GridView control.

But the following code fails

GridView1.Attributes.Add("onsort", "JSGridViewFunction()");

Please help.


Programmatically delete a .webpart file from wpcatalogs folder from an IIS website


We are using a third party wsp in our solution which directly adds the web parts into the web application store rather than the web part gallery(References to them are present in IIS site's wpcatalog directory). We want to remove these web part files so that the users will not be able to add these web parts to pages directly. Or any other modification so that users will not be able to add these directly. Is there a way we can do this programmatically?

Add webpart programmatically to page in sharepoint

Hi How to add webpart programmaticaly in sharepoint ? CheersMomo

Error when programmatically connect filter webpart with excel webpart

Hello, On MOSS 2007 SP2 64bit I am trying to programmatically connect a SPSlicerTextWebPart with an ExcelWebRenderer but I am getting the error: "The connection point "IFilterValues" on "g_046273fe_af27_4064_86b1_70f2c57c326c"(the excel webpart)   is disabled" and I can't find a way to enable it... I'm using the folowing code: using(SPLimitedWebPartManager webPartMgr = web.GetLimitedWebPartManager("Stats.aspx", PersonalizationScope.Shared)) { Microsoft.SharePoint.Portal.WebControls.SPSlicerTextWebPart filterWebPart = (Microsoft.SharePoint.Portal.WebControls.SPSlicerTextWebPart)webPartMgr.WebParts[0]; if (filterWebPart.ConnectionID == Guid.Empty) { filterWebPart.ConnectionID = Guid.NewGuid(); } webPartMgr.SaveChanges(filterWebPart); ProviderConnectionPoint providerCP = webPartMgr.GetProviderConnectionPoints(filterWebPart)[0]; Microsoft.Office.Excel.WebUI.ExcelWebRenderer excelWebPart = (Microsoft.Office.Excel.WebUI.ExcelWebRenderer)webPartMgr.WebParts[1]; if (excelWebPart.ConnectionID == Guid.Empty) { excelWebPart.ConnectionID = Guid.NewGuid(); } excelWebPart.AllowConnect = true; webPartMgr.SaveChanges(excelWebPart); ConsumerConnectionPoint consumerCP = webPartMgr.GetConsumerConnectionPoints(excelWebPart)[2]; TransformableFilterValuesToFilterValuesTransformer t = new TransformableFilterValue

Programmatically adding Calendar web part with summary view or custom view?

Within my feature I am adding a calendar web part to page.  I would like to specify the summary view (not the full graphic calendar view).  Is this possible? Is it possible to create a custom view and set the listviewwebpart to this custom view through code?   thx -davedave

Change webpart properties programmatically

I am attempting to modify the properties of another webpart when my webpart's button is clicked. The code compiles and runs, and stepping through it shows that the properties do change. However, they don't stay changed. This example attempts to toggle the visibility state, but other properties won't stay changed either. Any help is appreciated.     SPSecurity.RunWithElevatedPrivileges(delegate() { // get the site in this context using (SPSite SiteCollection = new SPSite(mySiteGuid)) { // get the web in this context SPWeb myWeb = SiteCollection.OpenWeb(myWebGuid); myWeb .AllowUnsafeUpdates = true; // Hide/display another webpart. Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null; mgr = myWeb.GetLimitedWebPartManager( "default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts) { // If this is the webpart we want to modify... if (myWebPart.Title == "Other Webpart Name") { // Toggle the visibility state. myWebPart.Visible = ! myWebPart.Visible; myWeb.Update(); break; } } } });

Adding a WebPart using SharePoint web services



I have a question regarding SharePoint web service, http://localhost/_vti_bin/webpartpages.asmx. I've managed to add a WebPart using AddWebPart web service method from the mentioned web service. The first argument of this method is pageUrl, which means that it expected that we have a page where the WebPart is added. Fiar enough. My question is: Is there a way to add this page programaticly using SharePoint web services? In SharePoint UI, I would click on"Site Actions" and then I would choose "Create Page" in order to do the same thing. I would like to do this using Sharepoint web services. Is this possible?

Thanks you,


Dynamically adding a checkbox to a gridview in a webpart


I have a webpart with a gridview that I would like to add a checkbox column to. I have read through a few articles but have not found one that actually works. Any help would be greatly appreciated.


Luis R. Lebron

need help on programmatically adding .pdf file type to File Type list in Search Admin


This is easily done in the GUI but how do I program this?

I looked here - http://msdn.microsoft.com/en-us/library/ms562090(v=office.12).aspx and they just say - Extensions are grouped within an ExtensionCollection object. Use the Create method to specify a new file name extension.

Great but how do I do that - I'm not a coder and I need some pointers

I loaded the sharepoint assemblies:

[System.Reflection.Assembly]::Load("Microsoft.Office.Server.Search, Version=, Culture=neutral,

[System.Reflection.Assembly]::Load("Microsoft.Sharepoint, Version=, Culture=neutral,

[System.Reflection.Assembly]::Load("Microsoft.Office.Server, Version=, Culture=neutral,

Where do I go from here?




Error in adding new link in summary link webpart after upgrading to sharepoint 2010



I have a weird error after upgrading my portal from sharepoint 2007 to sharepoint 2010 using attach database approach.

The error occurs when creating a new link in the summary link web part, so a pop up screen will show up, then if I click on Browse Button to link for an item an error occur, on the other hand if i click Browse Button to link an image then everything is working normally.

I checked the event viewer and here what I got, any Ideas?

Event code: 3005

Event message: An unhandled exception has occurred.

Event time: 23/10/2010 3:44:56 PM

Event time (UTC): 23/10/2010 12:44:56 PM Event ID: b74e380e0f6c4d3499feae1176557bcd Event sequence: 403 Event occurrence: 5 Event detail code: 0


Application information:

Programmatically adding user profile properties fails when adding a multivalued property


I have written a console application that adds a custom section to the User Profile Properties and then adds properties under that section. The code works fine when adding CoreProperties of type string (Single Value) and mapping each property to an Active Directory field. However the code always fails when mapping a string (Multi Value) property to an AD property. I have researched the errors I present below but cannot see what the solution might be.


    private static void AddCustomProperties(string strUrl)
      Console.WriteLine("Adding custom properties under section '" + DisplayName + "'.......");
      using (SPSite siteColl = new SPSite(strUrl))

        SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl);
        UserProfileConfigManager upcm = new UserProfileConfigManager(serviceContext);
        CorePropertyManager cpm = upcm.ProfilePropertyManager.GetCoreProperties();
        ProfilePropertyManager ppm = up

Sharepoint 2010 - Stuck Programmatically Adding a SharePoint Calendar Entry because of type "Person


How obscure is my question? I've had 40 reads without responses. Makes me feel better that I couldn't figure it out :-)

Programmatically Adding a SharePoint Calendar Entry

That is my goal and I am close. I am new to SharePoint and I am using the new approach with DataServiceContext.

Everything works except for adding "Person or Group" types. Can't find any good notes on this.


Update Webpart Assembly info programmatically



We have a requirement where in we need to update all the old custom webpart which are added to the portal with new Assembly information. The way we have planned is to create a console app, iterate through all the Pages Library withing each Site and Sub-site, get the WebPart Collection and once the "SPWebpartCollection" object is created, use System.Reflection.PropertyInfo and get all the property. I am done almost uptill here, but now stuck on how to proceed further. I would like to change the WebPart Assembly and Namespace information. The reason why this is required is, earlier earlier each webparts were having different dll. Now we have clubed all the webpart under one Assembly and the namespace are kept same now. But because the webpart were added to the page manually, they are holding the reference to the old assembly. The other way would be to remove the webpart and re-add the webpart which is not very much accepted when the number of sites and sub-sites involved in more than 1500.

Any solution would be really appreciated. Thanks.

Regards, Paddy

Cannot view webpart in browser after adding Group Properties


Ihave a customized web part, this can be shown properly in browser.

however, in the dataview, if I added "Collapse group by default ", it looks fine in sharepoint designer. But, when it goes to browser. i got the following error:

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

Please help ! ! !

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend