Emre Aslan Emre Aslan - 24 days ago 9
ASP.NET (C#) Question

How can I increment a value on page refresh?

I want to increase value while page refresh. How can I do?

My code:

protected void Page_Load(object sender, EventArgs e)
{
int evrno = 021006;
string EVRAKNO = "SP-";
if (Page.IsPostBack == false)
{
evrno = evrno + 1;
}

string EvrakNu = EVRAKNO + Convert.ToString(evrno);
txt_EvrakNo.Text = EvrakNu;
}

Answer

Woring solution:

protected void Page_Load(object sender, EventArgs e)
{

        int evrno = 21006;
        string EVRAKNO = "SP-";

        //save initial value in Session
        if (Session["evrno"] == null)
        {
            Session["evrno"] = evrno;
        }
        if (Page.IsPostBack == false)
        {
            //used the value saved in Session
            evrno = Convert.ToInt32(Session["evrno"]) + 1;

        }
        string EvrakNu = EVRAKNO + evrno.ToString();

        //save NEW value in Session again
        Session["evrno"] = evrno;

        txt_EvrakNo.Text = EvrakNu;
        //Response.Write(EvrakNu);
}