Monday 20 April 2015

Generate Random Alphanumeric Strings Like Letters&Numbers in Asp.Net C#

Generate Random Alphanumeric Strings


Generate Random Alphanumeric Strings Like Small & Captial Letters ,Numbers With Combine Particular Length String Display  Using Asp.Net C#.


                            DEMO


HTML CODING


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;
using System.Data.SqlClient;


public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {                      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        char[] CharsString = new char[10];
        Random random = new Random();

        for (int i = 0; i < CharsString.Length; i++)
        {
            CharsString[i] = chars[random.Next(chars.Length)];
        }

        string Result = new String(CharsString);
        lblRandomString.Text = Result;
    }
}
  











0 comments:

Post a Comment