Microsoft PlayGround

A Playground for Microsoft Technologies

ASP.NET Checkbox with confirmation message

For one of my assignments I had to create a checkbox that displays a confirmation message when you uncheck a checkbox. I thought I would share my solution with you guys.

 

First off al you will have to create a new class file that we will call ‘ConfirmationCheckbox’ the class will inherit from ‘System.Web.UI.WebControls.Checkbox’ (the normal checkbox). For our checkbox you have to override the ‘OnPreRender’ to add JavaScript to the page and the ‘AddAttributesToRender’ to add the onclick to the checkbox for the notification. Besides that you have to create a property for the confirmation text.

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Web.UI.WebControls;
 using System.Web.UI;
 using System.Globalization;

 namespace Motion10.SharePoint.WebControls {
     public class ConfirmationCheckBox : CheckBox {
         public string ConfirmationText { get; set; }

        protected override void OnPreRender(EventArgs e) {
             base.OnPreRender(e);
             this.Page.ClientScript.RegisterClientScriptResource(typeof(ConfirmationCheckBox), "Motion10.SharePoint.JavaScript.js");
         }

         protected override void AddAttributesToRender(HtmlTextWriter writer) {
             this.Attributes["onclick"] += string.Format(CultureInfo.CurrentCulture, "Confirmation(this, '{0}');", this.ConfirmationText);
             base.AddAttributesToRender(writer);
        }
    }
}

In the code sample above you see the overridden methods, in the ‘AddAttributesToRender’ we add a call to the JavaScript method to the attribute ‘onclick’. The JavaScript that we will create later on in this article needs two parameters the object in this case the checkbox (this) and the text for the confirmation (this.ConfirmationText).

 

The JavaScript will be added to the page in the OnPreRender method of the CheckBox. The JavaScript is a embedded resource in our dll. For that reason you have to use “Motion10.SharePoint.Notification.JavaScript.js”.

If you want to create a JavaScript file as embedded resource you have to do the following:

  1. Create a JavaScript file within your project.
  2. Right click on the file and choose properties.
  3. In the properties window set the Build Action to embedded resource.

After you have done this you can add the Resource to the ‘AssemblyInfo.cs’ file under the properties like this:

[assembly: WebResource("Motion10.SharePoint.JavaScript.js", "text/javascript")]

Finally you will have to point to the file by using the full assembly name followed by the filename. If you place the file in a folder you will also have to add the folder to the name.

 

Know we have got this out off the way we still have to create the JavaScript for the confirmation message.

function Confirmation(el, message) {
    if (!el.checked) {
       el.checked = !confirm(message);
    }
}

As you can see we have one method in the JavaScript file called Confirmation that needs to parameters. The ‘el’ stands for the checkbox and ‘message’ for the message that needs to be displayed. In the method we check if the checkbox is unchecked because we only want to display a notification when the checkbox is unchecked.

Javascript Confirmation

So when a user uncheck the checkbox a confirmation message will be shown (The message we entered as property of the checkbox). If the users selects ‘Ok’ the checkbox stays unchecked and when the user selects ‘Cancel’ the checkbox will stay checked and the “OnCheckChange” event of the checkbox will not be called.

Prompting for Credentials

Often people ask me a question why Windows keeps prompting to login when you open a document from SharePoint.

To automatically login you can change the settings that I have written down in this blog post: SharePoint prompts to login multiple time when opening a document

If you still have problems with windows that keeps prompting for credentials you should not stop the WebClient service like many blogs give as solution. Stopping this service is a resolution for this problem but not the correct solution. When you stop this service other problems can occur like:

  • When you open a document from SharePoint and press “Save” the save dialog will not open with the document library but with a local folder.

But what is the resolution I hear you thinking! The resolution for vista is a registry key setting.

  1. Go to start – run, and type regedit.
  2. When the registry editor window opens go to this path:
    • HKEY_LOCAL_MACHINE – SYSTEM – CurrentControlSet – Services – WebClient – Parameters.
  3. Right-click the ‘Parameters’ subkey and create a new Multi-String Value.
  4. Give the Multi-String Value the name ‘AuthForwardServerList’.
  5. Open the new value and type in the list of SharePoint server URL’s that are trusted and click ‘Ok’
  6. Close the registry editor.
  7. Reboot your PC or restart the WebClient Service : start – Administrative Tools – Services

The steps I have written down should work on a PC with Windows Vista SP1. If you guys have found another solution please let me know by placing a comment.

Using Windows Server as a Desktop Operating System

On this planet there are a lot of geeks (Including me) that run Windows Server 2008 (R2) as their desktop operating system.
I installed my development laptop with a dual boot of Windows 7 and Windows Server 2008 R2. The Windows Server 2008 R2 install is really a virtual hard disk that I setup as a boot device.

If there are some developers who would like to setup a Virtual hard disk as boot device I would recommend the following article:

I recommend an installation of a virtual hard disk on a hyper-v server. After the installation you can run ‘sysprep’ with the option ‘shutdown’ and copy the virtual hard disk to your computer. After that you can set it up as a boot device as explained in the article above.

After you have followed the steps (or installed Windows Server) you have a server environment as your desktop operation system, but it still isn’t like a Windows 7 or Windows Vista environment. If you would like your windows server installation to look like windows Vista or Windows 7 you have to install the ‘Desktop Experience’ feature.

The ‘Desktop experience’ feature includes programs like:

  • Windows Media Player
  • Windows Aero and other desktop themes
  • Video for Windows (AVI support)
  • Windows Defender

To install the ‘Desktop experience’ follow the following steps:

  • Open Server Manager: click Start, point to Administrative Tools, and click Server Manager.
  • In the Features Summary section, click Add features.
  • Select the Desktop Experience check box, and then click ‘Next’ and then click ‘Install’.

Now you are ready to get a real desktop experience from Windows Server, but the Aero theme still isn’t working. To get this working you will have to activate the “Themes” services from windows and set the startup type to automatic.

  • Click Start, click Run, type in services.msc, and then click OK.
  • In the list of installed services, right click Themes, and then click Properties.
  • In the startup section click automatic, click apply and the click Start. And then click OK to close the window.

After this configuration change your desktop needs to be restarted. After the reboot you can change the windows theme. By right clicking on the desktop and choosing ‘Personalize’ and selecting the Windows 7 Theme in case of windows server 2008 R2.

Microsoft Office SharePoint Server 2007 on Windows Server 2008 R2

A few days ago I started setting up an internal development environment for SharePoint. This environment needed to exist of a Domain server, Database server and of course a SharePoint Server.
The R2 of Windows Server 2008 was just released so I thought lets install everything on the R2 version. All went fine until I begun with the installation of SharePoint 2007.
The installation told me that the version that I was installing was not compatible with the server version. This error was shown because you van only install SharePoint 2007 SP2 on the R2 version of windows server 2009. We had no installation disk of SP2 (I don’t even think one exists, correct me if I’m wrong), so we had to merge the current installation (SharePoint 2007 SP1) with the updates of SP2.

Follow these steps to accomplish this:

  • Copy the installation folder from your installation disc to your local hard drive.
  • Download Microsoft Office SharePoint Server 2007 SP2 and the Windows SharePoint Services SP2.
  • Extract the downloaded updates files to the installation folder you copied from your disc. You have to make sure you extract the files to the upgrades folder. By doing the following:
    • [update filename] /extract:”[upgrade folder location of the folder you copied from the disc]“
    • For example:Wssv3sp2-kb953338-x64-fullfile-en-us.exe /extract:C:\Original\Updates
  • Make sure you extract both the updates (Download Microsoft Office SharePoint Server 2007 SP2 and the Windows SharePoint Services SP2).
  • When you have extracted the update files remove the “Wsssetup.dll” from the updates folder

Know you are ready to install Download Microsoft Office SharePoint Server 2007 SP2 on Windows Server 2008 R2 from the folder on your hard disk. For more information you can always read the technet article ( http://technet.microsoft.com/en-us/library/cc261890.aspx).

Login to Team Foundation Server 2008 SP1 with another account / from another domain

A few days ago I and my colleague Wesley had a lot of problems installing of Team Foundation Server on Windows Server 2008 with a Separate SQL Server 2008 and SharePoint Farm. After a couple days of hard work we finally got it running.

When we completed the installation we began testing it on our local systems. On our local system everything went fine but when we tried it on a Virtual Machine that we use for developing solution for SharePoint we could not connect to the Team Foundation Server.

The problem here was that the Virtual Machine has its own domain so the account that you are logged in with could not authenticate to the TFS server.

To get around this you have to specify a network account by following the following steps (Windows Server 2008):

1: Start – Control Panel
2: In the Control Panel select User Accounts.
3: On the left side of the screen select Manage your network passwords.

Windows Network Accounts

4: Click add and insert the right information.

Add Windows Network Account

5: Click “Ok” when you are done and on the other screen select “close”

Try connecting to the Team Foundation Server again. Now everything should work perfectly.