hii
How to autogenerate a unique number and assigned to a TexBox then save to database
Autogenerate number
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sreejesh SPRank #1,975 · 740 reputationPosted Jun 3, 2013, 10:38 PM EDT
Please use below code your problem is solved
aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
page.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["value"] = null;
}
}
protected void btnclick(object sender, EventArgs e)
{
if (ViewState["value"] != null)
{
int value = (int)ViewState["value"];
textvalue.Text = Convert.ToString(value + 1);
}
else
{
textvalue.Text = Convert.ToString(1);
}
int newValue = Convert.ToInt16(textvalue.Text);
ViewState["value"] =newValue;
}
}
}
thanks
sreejesh
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 4, 2013, 1:55 AM EDT
hi,
please provide more information.
because we don't know what is requirement?
are you going to insert it into database?
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 4, 2013, 5:59 AM EDT
Are you looking for auto-increment or random unique number generation?