Allow Only Number To TextBox Avoid Character Using RegularExpression Validation in Asp.Net C#

Allow Only Number  To TextBox  Avoid Character 


Textbox Enter Input Only Allowed Number  But Not Allow Character   RegularExpression Validation Using Asp.Net C#.

DEMO




HTML CODING


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
        <asp:TextBox ID="txtNumber" runat="server" Height="16px" AutoPostBack="True" ForeColor="#CC3300" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
    </form>
</body>
</html>



                           C# CODING


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {

    }  
  
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {


  if (System.Text.RegularExpressions.Regex.IsMatch(txtNumber.Text, "[^0-9]"))
        {

        Response.Write("<script>alert('Only Allowed Numbers')</script>");

            int count = txtNumber.Text.Count();

    txtNumber.Text = txtNumber.Text.Remove(txtNumber.Text.Length - count);

        }
        else
        {

            Response.Write("<script>alert('Valid Numbers')</script>");

        }
    }
}


First - Add New Web Form - Add TeextBox - AutoPostBack=True







Double Click TextBox - Add The Coding to Textbox_TextChanged








Next - Run [F5] The Program -  Enter TextBox Values Get Result














AutoComplete TextBox Search From DataBase Table in Using Windows Application C#

AutoComplete TextBox Search DataBase Table in Windows Application

Window Application Search TextBox Related Keyword Display Database Particular Table Record Display In Window Application.


 Auto Suggestion Box Master Page
 Auto Suggestion Box Multiple Table Search
 Auto Suggestion Ajax AutoCompleteExtender
 Auto Complete Search For WINDOW APPLICATION


                                     DEMO




                    C# Coding


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
      

        public Form1()
        {
            InitializeComponent();
        }


        SqlConnection con;


        public void dbcon()
        {

    con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Drizzle\Documents\Visual Studio 2012\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf;Integrated Security=True");

            con.Open();
       
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
           
          AutoCompleteStringCollection LocalDataTable = new AutoCompleteStringCollection();

            txtAutoComplete.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

            txtAutoComplete.AutoCompleteSource = AutoCompleteSource.CustomSource;

            txtAutoComplete.AutoCompleteCustomSource = LocalDataTable;

            dbcon();

            SqlCommand cmd = new SqlCommand("select countryname from country",con);     
            
            SqlDataReader rd = cmd.ExecuteReader();         

            if (rd.HasRows == true)
            {

               while (rd.Read())
               {

                   LocalDataTable.Add(rd[0].ToString());

               }
           }             
           
         }

       }
}



AutoCompleteMode :  Get & set control Automatic for Textbox

AutoCompleteSource: Get & set the source of complete String

AutoCompleteCustomSource: Get & set the AutoComplete Source 

Property is set to CustomSource

AutoCompleteStringCollection: Get data from Database To allow Bind 



to TextBox.



First - Add the New Window Form - Add the TextBox & Button 






Next - Insert The Values To DataBase Particular Table








Next - Add the  DataBase Connection - To Window Form Publically.







Path - Assign To SqlConnection








Next - Add the Coding For Form _Load  Geting Refresh








Next - Run[F5] The Program 







Textbox  Enter - A - Related CountryName Display From DataBase 






Textbox  Enter - U - Related CountryName Display From DataBase 








Textbox  Enter - I - Related CountryName Display From DataBase 












How to Get Complete Month & Day Name From Current DateTime Using Asp.Net C#

How to Get Complete Month & Day Name From Current DateTime


Get Current  Day & Month Full Name From DateTime  Using in C# .



                            Download Coding

                                                Download

                                     DEMO



Html Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
   
        <asp:Label ID="lblCalender" runat="server" ForeColor="#CC3300"></asp:Label>
  
        <asp:Button ID="btnDate" runat="server" OnClick="Button1_Click" Text="Date" />

        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Month" />

        <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Year" />
       
   
    </div>
    </form>
</body>
</html>


C# Coding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DateGet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
  
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        // Get Full  Name Of Current Day
       
        lblCalender.Text = DateTime.Now.ToString("dddd");

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
     
        // Get Full Name of Current Month

        lblCalender.Text = DateTime.Now.ToString("MMMM");


    }
    protected void Button3_Click(object sender, EventArgs e)
    {


        // Get Current year

        lblCalender.Text = DateTime.Now.ToString("yyyy");

    }
}



First Add The New Web Form -  Add Label & 

Buttons(Requireds)






Next - Day Button - Doule Click - Add Below Coding






Next - Month,Year Button - Doule Click - Add Below Coding







Next - Run[F5] - The Program -  Select Button Respective Results Display.


OUTPUT











Validation to Check Duplicate Records Before Inserting Using in Asp.Net C#

Validation to Check Duplicate Records Before Inserting


If UserName or Id Values Enter in  Manually  Avoid Duplicate Values Before Insert  to Validate Using  Asp.Net C#.


                                                        DEMO


   DOWNLOAD CODING



                          HTML CODING



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
      

        Username
        <asp:TextBox ID="txtUsername" runat="server" AutoPostBack="True"

            OnTextChanged="txtUsername_TextChanged" ></asp:TextBox>

        <asp:Label ID="Label1" runat="server" ForeColor="#CC3300" Visible="False"></asp:Label>
     


    </div>
    </form>
</body>
</html>

                        
                     C# CODING

  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Net;


public partial class Login : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    SqlDataReader rd;  
    string query;


    public void dbcon()
    {
        string connn = (System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con = new SqlConnection(connn);
        con.Open();

    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void txtUsername_TextChanged(object sender, EventArgs e)
    {
        dbcon();
        query = "select username from register";
        cmd = new SqlCommand(query, con);       
        rd = cmd.ExecuteReader();
        while(rd.Read())
        {
            Label1.Text = "";

            if(rd["username"].ToString() ==                                txtUsername.Text.ToString())

            {
                Label1.Visible = true;

                Label1.Text = "Already Exists";

                break;
           
            }
         
        }
    }
}




First Create New WebForm - Add the Label & Textbox Property Set AutuPostBack =True








Next - Label - Property Set Visible=True








Showing Html Coding








Next - DataBase - Table  -  Show The Existing Values








Next - Double Click - TextBox  - Add NameSpaces & DtaBase Connection







Double Click - TextBox  - Add The Coding 








Next - Run The Program - Check The Existing Values  
OUTPUT