HERE IN THIS .Net Tutorial WE WILL GENERATE RANDOM NUMBER IN ASP.NET AND C#
Step 1 :-WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="randomnumber.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Generate Random Number" OnClick="Button1_Click" />
<br>
<br>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#000099"></asp:Label>
</div>
</form>
</body>
</html>
Step 2 :- C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace randomnumber
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Random r = new Random();
int num = r.Next();
Label1.Text = num.ToString();
}
}
}