This type of value should be stored in
Session. This code will do what you are looking for (modify it appropriately for your specific needs):
<%@ Page Language="C#" %><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Random Number</title>
</head>
<body>
<form id="frmMain" runat="server">
<asp:TextBox runat="server" ID="txtGuess" />
<asp:Button runat="server" ID="btnGuess" Text="Guess" onclick="btnGuess_Click" />
<div>
<asp:Label runat="server" ID="lblGuess" />
</div>
</form>
</body>
</html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Random rnd = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
Session["RandomNumber"] = rnd.Next(0, 30);
}
}
protected void btnGuess_Click(object sender, EventArgs e)
{
int guess;
if (int.TryParse(txtGuess.Text, out guess))
{
int number = (int)Session["RandomNumber"];
lblGuess.Text = number.ToString() + "_" + guess.ToString();
}
}
</script>