Skip to main content

Posts

Showing posts with the label JavaScript

Prevent multiple postbacks in SharePoint 2013

The scenario:  Disabled the button after user’s click event. Prevent user from clicking it several times. The problem: If the button is disabled, the server side event handler is not fired. The solution: Set the property UseSubmitBehavior to false . Explanations :  Here is the working code of how to have disabled button after it is clicked: < asp : Button ID ="Button1" runat ="server" Text ="Do Postback" UseSubmitBehavior ="false"   OnClick ="Button1_Click" OnClientClick ="Validate(this)"   />         function Validate(thisObj)        {            thisObj.disabled = true ;            return true ;        } If you don't set the property UseSubmitBehavior your code in the handler Button1_Click won’t fire. I spend several hours in debugging...

Using SharePoint Attachments' controls with elevated security

The scenario:  Create custom forms for Add/Edit/Delete items to a list which is not accessible by the regular users. The forms should support working with attachments. The problem: The default SharePoint controls don’t work if the current user doesn’t have access to the list items. The solution: Use custom code for generating the SharePoint default HTML so the out-of-the-box javascript works correct. Explanations:  The scenario occurs when some list need to be hidden form the users. The list has broken security inheritance and users can't navigate directly to it. Working with its fields requires crating web warts or application pages with appropriate controls on them and server-side code running under elevated privileges. The issue here is that the OOTB (out-of-the-box) controls for Attachments don't work if the user doesn’t have access to the related list item. The OOTB controls are: AttachmentsField , AttachmentUpload , AttachmentButton . There is a lot of cod...

Custom Item in 'Sned To' menu

In my previous post I show how to put some javascript to all pages in a site collection using the delegate control. This is pretty common scenario and the approach with the AdditionalPageHead control works great. In this post I will use again the approach to solve another issue. The scenario:  Add a custom item in the ‘Send To’ section in the contextual menu for document.  The solution: Overwriting the default javascript function in core.js. The javascript function renders the new idem. A delegate control is used to bring the customizations on the pages in a particular web.  Code Sample: download from here Explanations: In such tasks the most normal approach will be using a custom action which most difficult part is to find the correct value for the Location property. The problem in our scenario is the fact that the Send To menu items are rendered only by javascript. There is no way to use custom action for it so the only option is to find a w...

Message to multiple site collections

Before some months I start following the TechNet forums about SharePoint. I read every week many questions, bookmark the interesting once, answer and research the others. I find it very useful and many new things are learn in a very fast way. Of course, the price of this is a time but let’s say I have a lot of it now J I notice one issue in tree similar questions so I decide to write a post about it. The scenario : how to add a message on a multiple site collections. This might be necessary when some farm maintenance is planned and the users must be notified. The solution : Site collection feature which use the JavaScript API to display the notification. The script is injected on the page with a delegate control AdditionalPageHead. Code Sample :   download from here   Explanation : SharePoint 2010 JavaScript client API has the function SP.UI.Status.addStatus which adds astatus message on a page. The code is simple: SP.UI.Status.ad...