Encrypting and decrypting connectionStrings section progrmatically is explained in this article from my blog.
Using aspnet_regiis.exe utility from Microsoft .NET framework it is quite easy and straight forward to encrypt and decrypt connectionStrings section in Web.config to protect sensitive data.
1. Open Visual studio command prompt window from Programs
2. Navigate to the folder where the application stored with in File system
3. Utilising aspnet_regiis.exe utility use below shown command to encrypt connectionStrings section.
c:/>aspnet_regiis -pef connectionStrings .
In the above command P stands for protection, E stands Encryption and F file system. . [DOT] for current location
Note: Make sure to navigate inside the website/web application project in file system.
That is it. ConnectionStrings section gets encrypted using RSA pubic key encryption to encrypt and decrypt data.
Note that in order to decrypt the same section use >aspnet_regiis –def connectionStrings .
In order to access controls with in Change Password control
1. Change the control to Template by going to design mode then smart tag
2. Choose Convert to Template
//Access the Cancel button which is with in ChangePassworTemplateContainer as below, it would be similar for other controls
//Get a reference to button, which is in ChangePasswordTemplateContainer
Button btnCancel = (Button)
if (btnCancel != null)
//Action to perform