Give validation to textbox that accepts min 6 charecters and max 12 charecters in Asp.net


For that add textbox control with the property MaxLength=12 and add RegularExpressionValidator with RegularExpression.

<asp:TextBox ID="TxtName" runat="server" MaxLength="12" Width="200px"></asp:TextBox>

<br />
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" 
ControlToValidate="TxtName"                                
ValidationExpression="(?=^.{6,12}$)(?=.*\d)(?=.*\W+)(?![.\n]).*$"
runat="server"
Text="Password must have minimum 6 characters & maximum 12 characters"></asp:RegularExpressionValidator>




Fill Years to Dropdownlist dynamically with some range in Asp.net


Filling Dropdownlist dynamically with the range of 1900 to this Year, for that
write the following code in PageLoad:



protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

             int thisYear = Convert.ToInt32(System.DateTime.Now.Year);

            for (int i = 1999; i <= thisYear; i++)
            {
                ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));

            }
            ListItem lsitem = new ListItem("Select Year", "0");
            ddlYear.Items.Insert(0, lsitem);
        }
    }








Fill Month Names and values to Dropdownlist dynamically in Asp.net


Add the following Namespace on the top for DateTimeFormatInfo:

using System.Globalization;


then write the following code in PageLoad:

protected void Page_Load(object sender, EventArgs e)
  {
               
   if (!Page.IsPostBack)
  {

        DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null);
        for (int i = 0; i < 12; i++)
        {
            ddlMonth.Items.Add(new ListItem(info.MonthNames[i], i.ToString()));
           
        }
        ListItem lsitem = new ListItem("Select Month", "0");
        ddlMonth.Items.Insert(0, lsitem);
    }

  }