Saturday, November 5, 2011

How many character remaining code in asp.net

Character count get increment and decrement when it get typed or deleted from textbox


 <script language="javascript">
    function count()
    {
        var keyid=event.KeyCode;

        var c=document.getElementById('TextBox1').value.length;
        if(c<=10)
        {
        document.getElementById('Text1').value=(10-c);
        }
        else
        {
           alert("Character exeed");
        }
  switch (keyid)
 {
    case 8:
    document.getElementById('Text1').value=( document.getElementById('Text1').value - c);
    case 46:
    document.getElementById('Text1').value=(document.getElementById('Text1').value - c);
 }
      
    }
  </script>


 <div>
  
        <asp:TextBox ID="TextBox1" runat="server" onKeyPress="count()" onKeyDown="count()" MaxLength="10"></asp:TextBox>
        <br />
      
    <label>10-></label> <input id="Text1" type="text" disabled="disabled" />
    </div>

Wednesday, November 2, 2011

CultureInfo Class - populate the dropdownlist with countries using culture in asp.net with vb

in Default.aspx.vb

Imports System.Globalization
Imports System.Collections.Generic



 Public Function getcountry() As List(Of String)
        Dim list As New List(Of String)()
        Dim culture As CultureInfo() = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures Or CultureTypes.SpecificCultures)

        For Each info As CultureInfo In Culture
            Dim info2 As New RegionInfo(info.LCID)
            If Not List.Contains(info2.EnglishName) Then
                List.Add(info2.EnglishName)
                List.Add(info2.DisplayName)

            End If

        Next
        Return List
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      DropDownList1.DataSource = getcountry()

        DropDownList1.DataBind()
         DropDownList1.Items.Insert(0, "select")



    End Sub