Jquery Script to Generate Random Number in Asp.Net C# VB.Net Aspx Page

In many forums i found a question “How to generate a Random Number using Jquery?”. Its easy to generate a Random number because Jquery provides us builtin Math library function named Math.random() to generate Random Numbers as well as lot of other math functionalities. To get the output you have to put a number range. Then use the mehod Math.random() to produce Random Numbers. You can also use this technique for dice, random image script, or random link generator.

Click here to get Javascript Random Number Generation Script.

Random Number Generation:

To do the JQuery Example please follw the below steps:
1. Add Jquery mini script first

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

2. Add a Server Side Button Control

<asp:Button ID="Button1" runat="server" Text="Generate Random Number" />

3. Add a Viv

<div id="divNumber"></div>

4. Add the Random Number Generation Script

    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%= Button1.ClientID %>').click(function () {
                var Random_Number = Math.ceil(Math.random() * 500); // Generate random number between 1 and 500               
                $("#divNumber").append("<b>The Number is: </b>" + Random_Number + "</br>");
                return false;

5. Now run the project.

Note: Full Code Example is same for both C# & VB.Net

Download Code Example C#        Download Code Example VB.Net

Posted in .Net, Asp.net, C#, JQuery, VB.Net
One comment on “Jquery Script to Generate Random Number in Asp.Net C# VB.Net Aspx Page
  1. Start Business in Delhi says:

    Very informative post for me as I am always looking for new content that can help me and my knowledge grow better.

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code