protected void Button1_Click(object sender, EventArgs e)
{
    // Get the file path for the current web request
    string webPath = Request.ApplicationPath;
    
    // Parse the leading forward slash 
    webPath = webPath.Substring(0, webPath.LastIndexOf('/'));

    // Get configuration object of the current web request
    Configuration config =
    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(webPath);

    // Create new connection setting from text boxes
    ConnectionStringSettings newConnSetting = new 
    ConnectionStringSettings(txtName.Text, txtValue.Text, txtProvider.Text);

    try
    {
        // Add the connection string to the collection
        config.ConnectionStrings.ConnectionStrings.Add(newConnSetting);
        
        // Save the changes
        config.Save();
    }
    catch (ConfigurationErrorsException cEx)
    {
        lblStatus.Text = "Status: " + cEx.ToString();
    }
    catch (System.UnauthorizedAccessException uEx)
    {
        // The ASP.NET process account must have read/write access to the directory
        lblStatus.Text = "Status: " + "The ASP.NET process account must have" + 
           "read/write access to the directory";
    }
    catch (Exception eEx)
    {
        lblStatus.Text = "Status: " + eEx.ToString();
    }

    // Reload the connection strings in the list box
    ShowConnectionStrings();
}
