Archive for Novembre 19th, 2007

Country dropdownlist control

CodeKeep C# Feed Novembre 19th, 2007

Description: the registry contains a list of countries for telephony so you can access that and build your list that way as long as your web server OS is up to date you get the latest country list

Link: http://www.codekeep.net/snippets/ff5770dd-6a54-4142-afe9-7bd57f571dc7.aspx

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Microsoft.Win32;

namespace DynamicWebSite.Framework
{
    public class CountryDropDownList : DropDownList
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

                        //would need some kind of state persistence / one time loading here like if(!Page.IsPostBack) or what have you
                this.DataSource = GetCountries();
                this.DataBind ();
            
        }


        private List<string> GetCountries()
        {
            List<string> returnValues = new List<string>();

            RegistryKey countries =
             Registry.LocalMachine.OpenSubKey(
              "Software\\Microsoft\\Windows\\CurrentVersion" +
              "\\Telephony\\Country List");

            if (countries != null)
            {
                // Get the list of subkeys,
                // which is actually the country code
                string[] subkeys = countries.GetSubKeyNames();

                foreach (string ccode in subkeys)
                {
                    // Open the subkey, to get the country name
                    RegistryKey country = countries.OpenSubKey(ccode);

                    // ..get the country name from country key
                    returnValues.Add(country.GetValue("Name").ToString());

                    // We're done using the key, we should close it
                    country.Close();
                }

                // It's now safe to close the country list key
                countries.Close();               
            }

            returnValues.Sort();
            return returnValues;
        }
    }
}

disable a button onclick

CodeKeep C# Feed Novembre 19th, 2007

Description: This disables a button on click good for file uploads

Link: http://www.codekeep.net/snippets/97f41326-1c5b-44b3-8bb5-815b64bc27c7.aspx

[buttonId].Attributes.Add("onclick", "javascript:" + [buttonId].ClientID + ".disabled=true;" + Page.ClientScript.GetPostBackEventReference([buttonId], ""));