As well as the client object model to get list & web details from SharePoint (from client side !) – you can also add a cool UI notification – like the ‘loading’ one shown here :
This uses the SP.UI.Notify.addNotification method – click the link to see some good examples at the MSDN site.
This is all great – but for SERVER side code – after a postback – from within C# – how do you do it ?!
The following C# method does the following :
- Input parameter – of the current PAGE object – either inside a webpart, or ASCX control, for example
- Input parameter – TEXT for the notification to display
- IMPORTANT (this is the gotcha) – need to ‘delay until script loaded’ for the SP.JS file – otherwise, you get a NULL reference exception – ExecuteOrDelayUntilScriptLoaded
- Add the JS to call to the actual method for the notification : SP.UI.Notify.addNotification
- Create a new ASP.NET literal control – which adds the ‘raw text’ to the page
- The notification is then shown, after the page refreshes – NICE !!
public static void AddSharePointNotification(Page page, string text)
StringBuilder stringBuilder = new StringBuilder();
//First wait until the SP.js is loaded, otherwise the notification doesn’t work
//gets an null reference exception
//add to the page
I’m sure this could be edited to do the SP.UI.Status.addStatus method also/instead.
Hope that’s helpful to you…!
** I’m planning to use this as a way of notifying the user of an EXCEPTION – within the end of a try-catch.