hii
How to autogenerate a unique number and assigned to a TexBox then save to database
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj PandeyPosted Jun 4, 2013, 9:59 AM
Are you looking for auto-increment or random unique number generation?
Jignesh TrivediPosted Jun 4, 2013, 5:55 AM
hi,
please provide more information.
because we don't know what is requirement?
are you going to insert it into database?
Sreejesh SPPosted Jun 4, 2013, 2:38 AM
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