Monday, July 7, 2008
I had a treeview inside a panel which in turn was inside an Ajax UpdatePanel.
The normal panel had its visibility set to false by default. And in the web part, clicking a button sets the visibility of that panel to true. I used this method to toggle the visibility of the treeview and related controls that resided with it on the panel.
Upon implementing this along with the UpdateProgress control and the EnsurePanelFix method, i started getting runtime errors whenever i tried to expand any of the treeview's nodes (all are collapsed by default).
After spending a lot of time troubleshooting and looking for answers, i discovered that the EnsurePanelFix method was causing the problem. And just for clarity, i'm not using the code provided by microsoft but rather the following simplified version:
"_spOriginalFormAction = document.forms.action; _spSuppressFormOnSubmitWrapper=true;",
And so i have found that the ONLY workaround for this is to dynamically add and remove the nodes of the treeview instead of making it visible and invisible each time the toggle is performed.
Everything else can be left on a panel and that panel can be set to visible=true or false as much as you like without having it affect anything else.
Just make sure that you NEVER touch the .visibility property of the TreeView control.
Tuesday, June 24, 2008
(Please note that this example takes place inside the Render(HtmlTextWriter writer) method:
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl))
SPList list = web.Lists["YourList"];
SPListItemCollection iCol = list.Items;
writer.Write("<tr><td><strong>Field name</strong></td><td><strong>Sample value (if any)</strong></td></tr>");
for (int i = 0; i < iCol.Fields.Count; i++)
writer.Write("</strong><br/>" + iCol.Fields[i].Description);
It contains all the default fields for a SPList item. (Remember that pages are essentially list items and the pages collection is essentially a list).
|Field name||Sample value (if any)|
|Content Type ID ||0x0100E65E7B14B0BC434CB9F70A29DDD8C22E|
|Approver Comments |
|DocumentTitle ||at work2.jpg|
|DocumentTitle ||at work2.jpg|
|File Type |
|Content Type ||Item|
|Modified ||6/24/2008 5:07 PM|
|Created ||2/20/2008 1:41 AM|
|Created By |
|Modified By |
|Has Copy Destinations |
|Copy Source |
|Workflow Version ||1|
|UI Version ||512|
|Approval Status ||Approved|
|Instance ID |
|Workflow Instance ID |
|URL Path ||/corporate/divisions/officeoftheceo/capacitydepoloyment/agencies/Lists/BusinessPortalUploadRecord/3_.000|
|Modified ||6/24/2008 5:07 PM|
|Created ||2/20/2008 1:41 AM|
|Item Type ||0|
|Effective Permissions Mask ||0x7fffffffffffffff|
|Unique Id ||389a8e63-0d5d-42c8-b8dc-a3702f566496|
|HTML File Type |
|Edit Menu Table Start ||3_.000|
|Edit Menu Table End ||3|
|Server Relative URL ||/corporate/divisions/officeoftheceo/capacitydepoloyment/agencies/Lists/BusinessPortalUploadRecord/3_.000|
|Encoded Absolute URL ||http://dvbmdas15:101/corporate/divisions/officeoftheceo/capacitydepoloyment/agencies/Lists/BusinessPortalUploadRecord/3_.000|
|File Name ||3_|
|Property Bag |
|Is Current Version ||Yes|
See next post for source-code on how to replicate this table.
This information is no longer applicable because Sharepoint 2007 SP1 supports AJAX. Sure you still have to modify a couple of things such as the web.config etc. (check my previous posts for a list of checks).
There are hundreds of websites out there that want to teach you how to use AJAX with Sharepoint 2007. Hell there are even several websites that want to teach you how to use AJAX with Sharepoint 2007 BETA!!!. People should surely take more responsibility for these posts and UPDATE or DELETE them when they are no longer applicable. Unfortunately this does not happen.
So let me tell you now that next time you google for information on how to do anything AJAX-related in sharepoint 2007 SP1, do yourself a favour and filter for articles written AFTER January 2008.
So you can safely ignore all those EnsureUpdatePanelFix() and similar pieces of code. Also you can safely ignore BaseWebPart and all other third-party webparts especially designed for ajax use in sharepoint. Using them will just give you more trouble than what its worth.
Wednesday, June 18, 2008
firstly make sure you have gone through the following list of prerequisites and notes:
Brief overview of requirements for using Ajax with Sharepoint 2007 web parts
- You have to make sure you programmatically create the control in the web part codebehind. Do it in the method "protected override void CreateChildControls()"
- Define the control as a global variable:
- Initialise the control in the CreateChildControls() method
Accordion1 = new Accordion();
- Make sure you give it an ID
Accordion1.ID = "Accordion1";
- Set the selected index
Accordion1.SelectedIndex = 0;
- Set other properties such as FadeTransitions and TransitionDuration etc
Accordion1.FadeTransitions = true;
Accordion1.FramesPerSecond = 20;
Accordion1.TransitionDuration = 100;
Accordion1.AutoSize = AutoSize.none;
- Add the accordion control to the page's controls collection
this.Controls.Add(Accordion1) (note: this still takes place in the CreateChildControls() method)
- Add panes in the following way:
AccordionPane pane1 = new AccordionPane()
string header = "this is the pane header";
string content = "this is the pane content";
- Remember that the following line of code must ALWAYS be at the end of the CreateChildControls() method:
- In your web part's Render(HtmlTextWriter writer) method
add the following at the location where you want the control to be displayed:
- Installed the Ajax Server Extensions
- Installed the AjaxControlToolkit
- Upgraded Sharepoint to Service Pack 1 or later
- Upgraded WSS 3.0 to Service Pack 1 or later
- Copied the AjaxControlToolkit.dll file to the bin folder of your portal under C:\Inetpub\wwwroot\wss\VirtualDirectories\yoursite\bin
- Updated the Web.config by adding relevant entries to support Ajax -> C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config (copy entries from web.config in a website you created by using the Ajax Enabled website starter kit in Visual Studio)
- FORGET ABOUT SMARTPART or any other 3rd party web parts that convert user controls into web parts. That was a crude workaround for versions of sharepoint before service pack 1.
- Use the web part development add-in for visual studio (use it to develop, deploy and debug)
- Add Scriptmanager control to your masterpage
<-- that is exactly where you must insert it
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
- Remember to publish your masterpage after adding the scriptmanager
- Toolkit controls have to be dynamically constructed in web part codebehind
- If your webparts are iterating through sub-sites remember to use the SpSecurity.Delegate functionality as described in an earlier post in this blog.
In a wide variety of scenarios, you might want to remove that web part from the specific page but you are unable to do this because the page cannot render.
To remedy this, you can use the Web Part Maintenance page for that specific page.
There is a long convoluted way of reaching this page but the straight-forward way of reaching it is:
> Add the following to the and of your URL: ?contents=1
So when typing something like (td valign= the editor will automatically insert: (td valign="" and place the cursor inbetween the two newly inserted quotation marks.
To enable this feature, follow these steps:
- From the menu select Tools | Options
- Expand the "Text Editor" node
- Expand the "HTML" node
- Click on the "Format" node
- Tick the "Insert attribute value quotes when typing" tickbox under the "Automatic formatting options" group. (see image below)
- Click OK
Thursday, March 6, 2008
I got the whole AJAX thing workin in MOSS2007 and its really cool, i've got this accordion control that im using. Thing is tho that it came time to test other user roles and i have this dummy contributor user and once i swapped to that user... it stopped working!!
I suddenly got the "Accordion1_AccordionExtender" requires ScriptManager blA bla bla... and i'm like ..what the frikken hell???
So after rummaging around on yahoo for issues with security i realised that i hadnt PUBLISHED THE FRICKEN MASTERPAGE!!!!!
So yeah hope that saves someone else from wasting all that crappy time!
Wednesday, March 5, 2008
I'm one of those persons.
The easiest most effective way to accomplish this is to use the SPSecurity.RunWithElevatedPrivelages(delegate()) method.
When i started looking into this i found several sources indicating that the correct way of using this method is as follows:
SPWeb objWeb = SPControl.GetContextWeb(Context);
using (SPSite objElevatedSite = new SPSite(objWeb.Site.ID))
using (SPWeb objElevatedWeb = objElevatedSite.OpenWeb())
// Allow unsafe updates because you can’t save changes
// during HTTP GET requests.
objElevatedWeb.AllowUnsafeUpdates = true;
SPNavigationNode node = new SPNavigationNode( å
“My Custom Node”, “http://node.url”, true);
And this worked fine for me when using Web User Controls. But somehow when i used this structure in web parts, i got the "using disposed SPWeb object no longer supported" error and it was difficult in this context to select an SPWeb which was not the current contextual web.
Thus i submit to thee THIS method which worked perfectly for me.
SPSecurity.CodeToRunElevated objCode = new SPSecurity.CodeToRunElevated(YourMethod);
In this scenario, "YourMethod" is a separate method which you call via the delegate.
Make sure to select any specific webs in the following way (or similar)
SPWeb selectedWeb = SPControl.GetContextWeb(Context).Webs[_targetSiteCollection];
(Actually I havent confirmed this but it worked for me and thats where i stopped).
Hope this helps.