Jul 20, 2005
Hello allI am developing a CountrySelector control (which I would like to sharewith anyone), but I am quite a newby in this custom control area.You can find it at:http://home.kabelfoon.nl/~juliusd/v...ntrySelector.vbSome questions I have are:- In what event should the items be added. In this case (PreRender)items added on every render (duh) and get duplicated when ViewState isenabled. Best would be if the items show up in the designer alreadybut only in designmode and not with <ListItem> in the HTML source.- How can I override ViewState get/set methods to only save thecurrent selection and not the whole collection? It will also need tosave whether it is the first render (for the use of the DefaultCountryproperty)- What behaviour to expect when an invalid countrycode is selected byconsuming (.net) code (e.g. in the DefaultCountry property)?- Is it possible to use System.Globalization to populate thecollection with country(code)'s?Thank you in advance.Hope to hear from youFreek VersteijnHere is the concept code:Imports System.ComponentModelImports System.Web.UIImports System.Web.UI.WebControls<ToolboxData("<{0}:CountrySelectorrunat=server></{0}:CountrySelector>")> Public Class CountrySelectorInherits System.Web.UI.WebControls.DropDownListProtected _DefaultCountry As String<Description("The initial country's code")> _Public Property DefaultCountry() As StringGetReturn _DefaultCountryEnd GetSet(ByVal Value As String)_DefaultCountry = ("" & Value).ToUpper()End SetEnd Property'TODO:' [ ] Move adding of items to other method?' [ ] Show DefaultCountry at first render' [ ] ViewState to only save the selected item' [ ] Use System.Globalization (RegionInfo.DisplayName or..EnglishName depending on CurrentCulture) for populating the Itemscollection if possibleProtected Overrides Sub OnPreRender(ByVal e As EventArgs)Items.Add(New ListItem("Albania", "AL"))Items.Add(New ListItem("Algeria", "DZ"))Items.Add(New ListItem("American Samoa", "AS"))Items.Add(New ListItem("Andorra", "AD"))Items.Add(New ListItem("Angola", "AO"))Items.Add(New ListItem("Anguilla", "AI"))Items.Add(New ListItem("Antarctica", "AQ"))Items.Add(New ListItem("Antigua/Barbuda", "AG"))Items.Add(New ListItem("Argentina", "AR"))Items.Add(New ListItem("Armenia", "AM"))Items.Add(New ListItem("Aruba", "AW"))Items.Add(New ListItem("Australia", "AU"))Items.Add(New ListItem("Austria", "AT"))Items.Add(New ListItem("Azerbaijan", "AZ"))Items.Add(New ListItem("Bahamas", "BS"))Items.Add(New ListItem("Bahrain", "BH"))Items.Add(New ListItem("Bangladesh", "BD"))Items.Add(New ListItem("Barbados", "BB"))Items.Add(New ListItem("Belarus", "BY"))Items.Add(New ListItem("Belgium", "BE"))Items.Add(New ListItem("Belize", "BZ"))Items.Add(New ListItem("Benin", "BJ"))Items.Add(New ListItem("Bermuda", "BM"))Items.Add(New ListItem("Bhutan", "BT"))Items.Add(New ListItem("Bolivia", "BO"))Items.Add(New ListItem("Bosnia", "BA"))Items.Add(New ListItem("Botswana", "BW"))Items.Add(New ListItem("Bouvet Island", "BV"))Items.Add(New ListItem("Brazil", "BR"))Items.Add(New ListItem("British Indian Ocean Territory","IO"))Items.Add(New ListItem("British West Indies", "WI"))Items.Add(New ListItem("Brunei Darussalam", "BN"))Items.Add(New ListItem("Bulgaria", "BG"))Items.Add(New ListItem("Burkina Faso", "BF"))Items.Add(New ListItem("Burma", "BU"))Items.Add(New ListItem("Burundi", "BI"))Items.Add(New ListItem("Cambodia", "KH"))Items.Add(New ListItem("Cameroon", "CM"))Items.Add(New ListItem("Canada", "CA"))Items.Add(New ListItem("Cape Verde", "CV"))Items.Add(New ListItem("Cayman Islands", "KY"))Items.Add(New ListItem("Central Africa", "CF"))Items.Add(New ListItem("Chad", "TD"))Items.Add(New ListItem("Chile", "CL"))Items.Add(New ListItem("China", "CN"))Items.Add(New ListItem("Christmas Island", "CX"))Items.Add(New ListItem("Cocos (Keeling) Islands", "CC"))Items.Add(New ListItem("Colombia", "CO"))Items.Add(New ListItem("Comoros", "KM"))Items.Add(New ListItem("Congo", "CG"))Items.Add(New ListItem("Cook Islands", "CK"))Items.Add(New ListItem("Costa Rica", "CR"))Items.Add(New ListItem("Cote D'Ivoire", "CI"))Items.Add(New ListItem("Croatia", "HR"))Items.Add(New ListItem("Cuba", "CU"))Items.Add(New ListItem("Cyprus", "CY"))Items.Add(New ListItem("Czech Republic", "CZ"))Items.Add(New ListItem("Denmark", "DK"))Items.Add(New ListItem("Djibouti", "DJ"))Items.Add(New ListItem("Dominica", "DM"))Items.Add(New ListItem("Dominican Republic", "DO"))Items.Add(New ListItem("East Timor", "TP"))Items.Add(New ListItem("Ecuador", "EC"))Items.Add(New ListItem("Egypt", "EG"))Items.Add(New ListItem("El Salvador", "SV"))Items.Add(New ListItem("Equatorial Guinea", "GQ"))Items.Add(New ListItem("Eritrea", "ER"))Items.Add(New ListItem("Estonia", "EE"))Items.Add(New ListItem("Ethiopia", "ET"))Items.Add(New ListItem("Faeroe Islands", "FO"))Items.Add(New ListItem("Falkland Islands", "FK"))Items.Add(New ListItem("Fiji", "FJ"))Items.Add(New ListItem("Finland", "FI"))Items.Add(New ListItem("France", "FR"))Items.Add(New ListItem("French Polynesia", "PF"))Items.Add(New ListItem("French Southern Territories", "TF"))Items.Add(New ListItem("Gabon", "GA"))Items.Add(New ListItem("Gambia", "GM"))Items.Add(New ListItem("Gaza", "XA"))Items.Add(New ListItem("Georgia", "GE"))Items.Add(New ListItem("Germany", "DE"))Items.Add(New ListItem("Ghana", "GH"))Items.Add(New ListItem("Gibraltar", "GI"))Items.Add(New ListItem("Greece", "GR"))Items.Add(New ListItem("Greenland", "GL"))Items.Add(New ListItem("Grenada", "GD"))Items.Add(New ListItem("Guadeloupe", "GP"))Items.Add(New ListItem("Guam", "GU"))Items.Add(New ListItem("Guatemala", "GT"))Items.Add(New ListItem("Guiana", "GF"))Items.Add(New ListItem("Guinea", "GN"))Items.Add(New ListItem("Guinea-Bissau", "GW"))Items.Add(New ListItem("Guyana", "GY"))Items.Add(New ListItem("Haiti", "HT"))Items.Add(New ListItem("Heard And Mcdonald Islands", "HM"))Items.Add(New ListItem("Held Territories", "XH"))Items.Add(New ListItem("Honduras", "HN"))Items.Add(New ListItem("Hong Kong", "HK"))Items.Add(New ListItem("Hungary", "HU"))Items.Add(New ListItem("Iceland", "IS"))Items.Add(New ListItem("India", "IN"))Items.Add(New ListItem("Indian Ocean Islands", "XI"))Items.Add(New ListItem("Indonesia", "ID"))Items.Add(New ListItem("Iran", "IN"))Items.Add(New ListItem("Iraq", "IQ"))Items.Add(New ListItem("Ireland", "IE"))Items.Add(New ListItem("Israel", "IL"))Items.Add(New ListItem("Italy", "IT"))Items.Add(New ListItem("Jamaica", "JM"))Items.Add(New ListItem("Japan", "JP"))Items.Add(New ListItem("Jordan", "JO"))Items.Add(New ListItem("Kazakhstan", "KZ"))Items.Add(New ListItem("Kenya", "KE"))Items.Add(New ListItem("Kiribati", "KI"))Items.Add(New ListItem("Korea", "KR"))Items.Add(New ListItem("Kuwait", "KW"))Items.Add(New ListItem("Kyrgyzstan", "KG"))Items.Add(New ListItem("Laos", "LA"))Items.Add(New ListItem("Latvia", "LV"))Items.Add(New ListItem("Lebanon", "LB"))Items.Add(New ListItem("Lesotho", "LS"))Items.Add(New ListItem("Liberia", "LR"))Items.Add(New ListItem("Libya", "LY"))Items.Add(New ListItem("Liechtenstein", "LI"))Items.Add(New ListItem("Lithuania", "LT"))Items.Add(New ListItem("Luxembourg", "LU"))Items.Add(New ListItem("Macau", "MO"))Items.Add(New ListItem("Macedonia", "MK"))Items.Add(New ListItem("Madagascar", "MG"))Items.Add(New ListItem("Malawi", "MW"))Items.Add(New ListItem("Malaysia", "MY"))Items.Add(New ListItem("Maldives", "MV"))Items.Add(New ListItem("Mali", "ML"))Items.Add(New ListItem("Malta", "MT"))Items.Add(New ListItem("Marshall Islands", "MH"))Items.Add(New ListItem("Martinique", "MQ"))Items.Add(New ListItem("Mauritania", "MR"))Items.Add(New ListItem("Mauritius", "MU"))Items.Add(New ListItem("Mayotte", "YT"))Items.Add(New ListItem("Mexico", "MX"))Items.Add(New ListItem("Micronesia", "FM"))Items.Add(New ListItem("Moldova", "MD"))Items.Add(New ListItem("Monaco", "MC"))Items.Add(New ListItem("Mongolia", "MN"))Items.Add(New ListItem("Montserrat", "MS"))Items.Add(New ListItem("Morocco", "MA"))Items.Add(New ListItem("Mozambique", "MZ"))Items.Add(New ListItem("Myanmar", "MM"))Items.Add(New ListItem("Namibia", "NA"))Items.Add(New ListItem("Nauru", "NR"))Items.Add(New ListItem("Nepal", "NP"))Items.Add(New ListItem("Netherlands", "NL"))Items.Add(New ListItem("Netherlands Antilles", "AN"))Items.Add(New ListItem("New Caledonia", "NC"))Items.Add(New ListItem("New Zealand", "NZ"))Items.Add(New ListItem("Nicaragua", "NI"))Items.Add(New ListItem("Niger", "NE"))Items.Add(New ListItem("Nigeria", "NG"))Items.Add(New ListItem("Niue", "NU"))Items.Add(New ListItem("Norfolk Island", "NF"))Items.Add(New ListItem("North Korea", "KP"))Items.Add(New ListItem("Northern Ireland", "XB"))Items.Add(New ListItem("Northern Mariana Islands", "MP"))Items.Add(New ListItem("Norway", "NO"))Items.Add(New ListItem("Oman", "OM"))Items.Add(New ListItem("Pakistan", "PK"))Items.Add(New ListItem("Palau", "PW"))Items.Add(New ListItem("Panama", "PA"))Items.Add(New ListItem("Papua New Guinea", "PG"))Items.Add(New ListItem("Paraguay", "PY"))Items.Add(New ListItem("Peru", "PE"))Items.Add(New ListItem("Philippines", "PH"))Items.Add(New ListItem("Pitcairn", "PN"))Items.Add(New ListItem("Poland", "PL"))Items.Add(New ListItem("Portugal", "PT"))Items.Add(New ListItem("Puerto Rico", "PR"))Items.Add(New ListItem("Qatar", "QA"))Items.Add(New ListItem("Reunion", "RE"))Items.Add(New ListItem("Romania", "RO"))Items.Add(New ListItem("Russia", "RU"))Items.Add(New ListItem("Rwanda", "RW"))Items.Add(New ListItem("Saint Lucia", "LC"))Items.Add(New ListItem("San Marino", "SM"))Items.Add(New ListItem("Sao Tome And Principe", "ST"))Items.Add(New ListItem("Saudi Arabia", "SA"))Items.Add(New ListItem("Scotland", "WY"))Items.Add(New ListItem("Senegal", "SN"))Items.Add(New ListItem("Seychelles", "SC"))Items.Add(New ListItem("Sierra Leone", "SL"))Items.Add(New ListItem("Singapore", "SG"))Items.Add(New ListItem("Slovak Republic", "SK"))Items.Add(New ListItem("Slovenia", "SI"))Items.Add(New ListItem("Solomon Islands", "SB"))Items.Add(New ListItem("Somalia", "SO"))Items.Add(New ListItem("South Africa", "ZA"))Items.Add(New ListItem("South Georgia", "GS"))Items.Add(New ListItem("Spain", "ES"))Items.Add(New ListItem("Sri Lanka", "LK"))Items.Add(New ListItem("St. Helena", "SH"))Items.Add(New ListItem("St. Kitts & Nevis", "KN"))Items.Add(New ListItem("St. Pierre", "PM"))Items.Add(New ListItem("St. Vincent & The Grenadines", "VC"))Items.Add(New ListItem("Sudan", "SD"))Items.Add(New ListItem("Suriname", "SR"))Items.Add(New ListItem("Svalbard And Jan Mayen Islands","SJ"))Items.Add(New ListItem("Swaziland", "SZ"))Items.Add(New ListItem("Sweden", "SE"))Items.Add(New ListItem("Switzerland", "CH"))Items.Add(New ListItem("Syria", "SY"))Items.Add(New ListItem("Taiwan", "TW"))Items.Add(New ListItem("Tajikistan", "TJ"))Items.Add(New ListItem("Tanzania", "TZ"))Items.Add(New ListItem("Thailand", "TH"))Items.Add(New ListItem("Togo", "TG"))Items.Add(New ListItem("Tokelau", "TK"))Items.Add(New ListItem("Tonga", "TO"))Items.Add(New ListItem("Trinidad And Tobago", "TT"))Items.Add(New ListItem("Tunisia", "TN"))Items.Add(New ListItem("Turkey", "TR"))Items.Add(New ListItem("Turkmenistan", "TM"))Items.Add(New ListItem("Turks And Caicos Islands", "TC"))Items.Add(New ListItem("Tuvalu", "TV"))Items.Add(New ListItem("U.S. Minor Outlying Islands", "UM"))Items.Add(New ListItem("U.S.A.", "US"))Items.Add(New ListItem("Uganda", "UG"))Items.Add(New ListItem("Ukraine", "UA"))Items.Add(New ListItem("United Arab Emirates", "AE"))Items.Add(New ListItem("United Kingdom", "GB"))Items.Add(New ListItem("Uruguay", "UY"))Items.Add(New ListItem("Uzbekistan", "UZ"))Items.Add(New ListItem("Vanuatu", "VU"))Items.Add(New ListItem("Vatican City State", "VA"))Items.Add(New ListItem("Venezuela", "VE"))Items.Add(New ListItem("Viet Nam", "VN"))Items.Add(New ListItem("Virgin Islands (British)", "VG"))Items.Add(New ListItem("Virgin Islands (U.S.)", "VI"))Items.Add(New ListItem("Wales", "WX"))Items.Add(New ListItem("Wallis And Futuna Islands", "WF"))Items.Add(New ListItem("Western Sahara", "EH"))Items.Add(New ListItem("Western Samoa", "WS"))Items.Add(New ListItem("Yemen", "YE"))Items.Add(New ListItem("Yugoslavia", "YU"))Items.Add(New ListItem("Zambia", "ZM"))Items.Add(New ListItem("Zimbabwe", "ZW"))MyBase.OnPreRender(e)End SubProtected Overrides Function SaveViewState() As ObjectEnd FunctionProtected Overrides Sub LoadViewState(ByVal savedState As Object)End SubEnd Class
View 2 Replies
View Related