Friday 27 February 2015

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

No comments    
categories: , , ,
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>");

        }
    }
}




















Wednesday 25 February 2015

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



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.

                    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());

               }
           }             
           
         }

       }
}












































Friday 20 February 2015

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

No comments    
categories: , , ,
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");

    }
}


















Wednesday 18 February 2015

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

No comments    
categories: , ,
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;
           
            }
         
        }
    }
}