Generate Random Numbers in Button_Click Event Get Textbox Values Using Asp.Net C#

Generate Random Numbers in Button_Click Event Get Textbox Values

Generate Random Numbers Given Input From TextBox  Click The Button Event Display The Random Numbers To Labels.

                           Download Coding



<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
                <asp:Label ID="Label1" runat="server" 
               Text="Minimum Range"></asp:Label>
             <asp:TextBox ID="txtMinimumRange"
                <asp:Label ID="Label2" runat="server" 
                     Text="Maximum Range"></asp:Label>
                    <asp:TextBox ID="txtMaximumRange" 
            <tr><td colspan ="2">
                <asp:Button ID="RandomNumber" runat="server" OnClick="RandomNumber_Click" Text="Get Random" />
                <br />
                        <asp:Label ID="Label3" runat="server" Font-                           Size="X-Large" 
             Text="Generate Random Numbers"></asp:Label>
                    <asp:Label ID="lblGetRandom1" 
        runat="server" ForeColor="#9900CC" Font-Size="Large">
                        <asp:Label ID="lblGetRandom2" runat="server" 
              ForeColor="#CC3300" Font-Size="Large"></asp:Label>
                        <asp:Label ID="lblGetRandom3" runat="server" 
         Font-Size="Large" ForeColor="#3333CC"></asp:Label></td></tr>



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

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

    protected void RandomNumber_Click(object sender, EventArgs e)
        // r.Next(MinimumValue,MaximumValue);

        if (Convert.ToInt32(txtMinimumRange.Text) < Convert.ToInt32(txtMaximumRange.Text))

            Random r = new Random();

            lblGetRandom1.Text = r.Next(Convert.ToInt32(txtMinimumRange.Text), Convert.ToInt32(txtMaximumRange.Text)).ToString();

            lblGetRandom2.Text = r.Next(Convert.ToInt32(txtMinimumRange.Text), Convert.ToInt32(txtMaximumRange.Text)).ToString();
            lblGetRandom3.Text = r.Next(Convert.ToInt32(txtMinimumRange.Text), Convert.ToInt32(txtMaximumRange.Text)).ToString();



            Response.Write("<script>alert('Number(s) Range Not Valid')</script>");



First Create New WebForm - Add  Textboxes & Labels  for Required

Next - Create Random Object - Assign The TextBox Convert to Integer

Next - Run[F5] The WebForm - Give The Input - Button Click  - Random Numbers Generate


Post a Comment